Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When recovering chars, still give them the char type, instead of &str #57384

Closed
estebank opened this issue Jan 6, 2019 · 5 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-type-system Area: Type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@estebank
Copy link
Contributor

estebank commented Jan 6, 2019

test/ui/parser/lex-bad-char-literals-3.stderr shouldn't emit a type error.

@estebank estebank added A-type-system Area: Type system A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Jan 6, 2019
@estebank
Copy link
Contributor Author

estebank commented Jan 7, 2019

This line would have to be changed to use token::Char:

return Ok(token::Literal(token::Str_(Symbol::intern("??")), None))

Ideally, we would add a new literal type Err here

#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub enum Lit {
Byte(ast::Name),
Char(ast::Name),
Integer(ast::Name),
Float(ast::Name),
Str_(ast::Name),
StrRaw(ast::Name, u16), /* raw str delimited by n hash symbols */
ByteStr(ast::Name),
ByteStrRaw(ast::Name, u16), /* raw byte str delimited by n hash symbols */
}

that will later be interpreted to be of type TyErr, in order to avoid having any type errors involving this problematic literal, regardless of wether a &str or a char were expected.

@JohnTitor
Copy link
Member

@estebank I wanna tackle this, but I don't know how to add a new literal type Err.
If you have time, please tell me.

@estebank
Copy link
Contributor Author

estebank commented Jan 8, 2019

@JohnTitor That would be the "hard" way of solving this. That would entail adding a new Lit variant, in the code linked above, deal with the fallout of doing so (most likely by ignoring it in most places) and transforming it to a TyErr when giving it a type (it is receiving TyStr at the moment). You should be able to find it by following the errors after adding the variant, but if not ping me and we can look at it together.

@JohnTitor
Copy link
Member

@estebank I want to open a PR for fixing this issue, can I ask you to review?

@estebank
Copy link
Contributor Author

@JohnTitor of course! Just add r? @estebank to the description of the PR.

bors added a commit that referenced this issue Jan 20, 2019
Implement new literal type `Err`

Fixes #57384

I removed `return Ok`, otherwise, two errors occur. Any solutions?

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST A-type-system Area: Type system E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

2 participants