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
Confusing 'invalid indentation' errors reported when indentation is not at fault #15667
Comments
maybe add an example from #10229 which is a common pitfall (in particular #10229 (comment)), which was closed as wontfix due to noone having stepped up to work on it |
One that I almost reported separately is type
Odd = ref object
id: int
proc `=copy`(dest: var Odd; source: Odd) {.error.} Which yields
What I didn't notice until I was writing up the issue is that the I'll give this feature a try. |
and yet another bug report that was just filed that's the same as this: #16232 I'm bumping this up to medium priority since it seems to trip so many people (and would generally improve user experience for everyone) |
Since my issue is a duplicate of this one, I'll write my findings here @timotheecour I kind of got curious, and started looking into the parser code to debug it for my cases. I narrowed it down to the Looking into the grammer, I believe If this was useful, I am happy to look into the other cases and sees what's going on. |
@NebulaFox please make a PR since you've started looking at this; I'd recommend focusing on improving at least just 1 common case for a start. proc fn() {.exportc.}
echo 1
=> instead:
|
@timotheecour I have not done any code changes yet, just debugging at the moment. Looking at the case that you have provided, I think error message I could create a PR with removal of the emitting error in Removing the emitting error from
Ideally we want the parser to mention a missing equals when it detects something that looks like an implementation on a procedure. The parser only has history as far back as the context it is in. The context of As far as I can see, the parser is behaving correctly, but lacks anyway to infer user intent. I propose that we add a layer, to or above, the parser, that can then keep track of things to infer user intent to give better error messages. We can then use the above cases to test the compiler against and determine the correct error message. I am not fully aware if the test suit is capable of handling such integration test/blackboxing testing. Thoughts? |
I have a candidate PR: timotheecour#418 that fixes 1 of the most common issues:
the test suite (tests/) can do anything, including calling the compiler directly and verifying the error message you get is as expected |
An unneeded closing parenthesis triggers the I guess something like
|
#16397 was merged; see future work mentioned in that PR |
refs nim-lang#15667 improve invalid indentation errors, report when & where `…
… where `=` could be missing (nim-lang#16397) * refs nim-lang#15667 improve invalid indentation errors * also show line info where = is missing * add test * add more tests
Compilation can fail with "Error: invalid indentation" given code that visibly lacks any indentation problems.
should be: expression expected, but found ...
vs. the more useful message from this complete program:
should be: expression has no type (or is ambiguous)
vs. the still confusing
vs.
should be: expression ... has no type (or is ambiguous)
vs.
should be: type mismatch
vs.
vs.
Additional Information
I've run into this personally, and just fixed the error and moved on, but it's still confusing to have to look and wonder if indentation is really invalid or not.
I imagine it's come up a lot in IRC; here's the latest occurrence: https://irclogs.nim-lang.org/21-10-2020.html#08:44:57
The last example is a variation of issue #11020
It's mentioned in #14952 that this error is
Possible mitigation
When nim fails to compile with an error that is merely "invalid indentation", it could link to a nim-lang.org page showing the other ways that this error might be triggered, or it could copy rustc a bit and add an additional message like
and that command can dump other ways to trigger this error into a pager.
The text was updated successfully, but these errors were encountered: