-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tuple struct field is parsed as float #1109
Comments
In the case of pub struct S;
impl S {
pub fn blah(&self) {}
}
struct T(S);
impl T {
fn foo(&self) {
self.0.<|>
}
} It looks like "0." is treated as a LITERAL:
|
Shouldn't |
That is expected, b/c
I haven't looked at this at all, it might be the case that "nothing works b/c nothing is supported", but it shouldb't be too hard to fix. I suggest just tracing back from the completion to see where we get wrong results. |
In principle, this should work, but there are no tests for typing |
The As an aside I couldn't debug this at all under windows and my vm likes to churn at 100% disk usage :D |
I have opened #1117 to add inference support to tuple struct indexing. However, this doesn't fix the issue as the lexer still finds a float literal in the autocompletion case and I don't know how to recover and parse it as int + dot. |
1117: [WIP] Tuple struct index inference r=matklad a=robojumper The first commit adds a helper struct `ast::FieldKind` to facilitate inference. The second commit adds a slightly modified test from #1109 while mentioning that there is a problem with how we're handling tuple indexing / floats. cc #1109 Co-authored-by: robojumper <[email protected]>
So the problem here is that we can't properly analyze incomplete file due to stupid lexer :) The tree for
is
Note that we have We probably will need to patch completion context as well: Question: why don't we fix the parser/lexer instead? It seems like this require the parser to know the text of the tokens, or for the lexer to know the preceding token, both of which seem less than ideal. But maybe I am missing some clean way to fix this? |
We do not need to know a whole token, we only need to know prev char is a "DOT", such that we only need to add a edit: grammer and typo |
a single char wouldn't be enough: |
Here's a simple reproduction. This infers fn main() {
let fld = ((0,),).0.0;
} |
Can I try to fix this one? 👀 |
Sure :-). |
I don't think this is going to be properly fixable without fixing it at the parser/lexer stage. Consider the way
Because I think that leaves 2 options: Option A – change the lexer: I've played with the idea of changing how floats are lexed at the This makes the lexer output look somewhat "ugly" – why would floats be multiple tokens? –, but from a compiler engineering perspective seems like the more "correct" way of doing things as it avoids lexer hacks. Option B – Put a 'lexer hack' in the parser: Another alternative would be to allow the parser to modify its input tokens while it's parsing them. Presumably we could tuck away the code that does this somewhere, to avoid having the parser "know" token contents, and just have it call rustc and syn both implement option B, because they are both lossy one-way parsers and that's simplest for them. I'm not quite sure which solution would be architecturally simpler for us but would appreciate some input, because I don't like this bug and would like to get it fixed :) |
…hievink internal: Add a `Converter` type for token conversion Makes it easier to produce multiple tokens from a single rustc token, if that's how we want to approach #1109
Sadly the fix caused a lot of downstream bugs, so I've reverted it in #12241 for now |
Another old related issue #5429 |
I've implemented an even more hacky "Option B" from above here: cynecx@cc7ba82. Fair warning: It is far from being upstreamable or PR worthy, but works if you really need it. |
Hmm, looking at this, I wonder if we can just encode the split as an extra event with option B? The main question is how to encode the split position (or if we have to just split on demand later) |
#14084 fixes this mostly. We still incorrectly parse it if it's passed as a macro input where an expression fragment is expected. |
The text was updated successfully, but these errors were encountered: