-
Notifications
You must be signed in to change notification settings - Fork 41
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
Don't crash on parse errors in deriving clauses #365
Conversation
The haskell parser returns '<unknown>.hs' if no path is explicitly given.
The line numbers from the haskell parser are wrong, it's easier to just report the whole pragma
It would also be possible to adjust the haskell parser to have a more accurate location, using similar code to the one used for foreign pragmas: Lines 38 to 45 in 22f37f5
The issue with that is that we don't know exactly how far into the line the It might however be worthwhile to provide the list of extensions to the haskell parser for deriving clauses, like the |
Thanks for the PR! I generally agree that having a more precise error location would be nice but here the issue seems rather minor so I would propose just merging this PR as is. |
I agree. I believe that getting the more precise location reliably is currently blocked by getting more range information from the Agda parser. More specifically: We only get the range of the full pragma, not the range of the string contents we get from it, so the best we could do is to guess that there is only one whitespace between each keyword and calculate how long the |
Ok, then let's go ahead and merge this. |
@jespercockx btw, on a related note: the code currently doesn't report an error on invalid keywords after In the function Lines 85 to 102 in 22f37f5
The final line ignores errors: Line 102 in 22f37f5
This means that this is accepted: record Foo : Set where
{-# COMPILE AGDA2HS Foo "&"€%(€&( #-} However, getting precise error location for this would have the same issue, so we would have to either give an imprecise error or make a guess (that will be true 99% of the time). But I guess the lack of precision doesn't matter too much there either. |
I'm not sure if it's intentional or not, I think it's been like that since the original implementation by @UlfNorell |
It turns out that if you don't specify a file-name, then the Haskell parser haskell-src-exts uses the filename
<unknown>.hs
,which we afterwards try to parse as an absolute filepath to extract the location of the error, which causes a crash.
Since the location from the Haskell parser wouldn't be accurate anyways, we change it to just report the entire pragma as the location of the error.
This PR also makes the code for converting Haskell locations into Agda locations return
Nothing
for the filename, instead of crashing if there is no valid filename in the error. This might not be desired since we should be able to provide a more helpful filename and location and this could make it easier to miss the issues with bad error reporting. That change currently has no impact, since this PR also prevents it from triggering.Fixes #351