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

Parsers likely contain list span mistakes #277

Open
raehik opened this issue Jul 28, 2023 · 0 comments
Open

Parsers likely contain list span mistakes #277

raehik opened this issue Jul 28, 2023 · 0 comments

Comments

@raehik
Copy link
Collaborator

raehik commented Jul 28, 2023

#276 fixes what appears to be a mistake in the F77 parser, where a span isn't set properly: a list is reversed before being placed in the AST, but the span uses the yet-reversed list. The problematic call was getTransSpan:

instance {-# OVERLAPPABLE #-} (Spanned a, Spanned b) => SpannedPair a b where
getTransSpan x y = SrcSpan l1 l2'
where SrcSpan l1 _ = getSpan x
SrcSpan _ l2' = getSpan y

which calls getSpan on a list:

instance (Spanned a) => Spanned [a] where
getSpan [] = error "Trying to find how long an empty list spans for."
getSpan [x] = getSpan x
getSpan (x:xs) = getTransSpan x (last xs)
setSpan _ _ = error "Cannot set span to an array"

And following the recursive getTransSpan, we see that by calling this on a reversed list, we accidentally span to the end of the first element instead of the last. Spanning requires things to go from left to right, it doesn't re-order automagically.

I noted another likely mistake in the F2003 parser. This probably happens a handful of times in the parsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant