Amend fix for correct placement of file header pragmas (#1958) #2078
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hi again, I noticed two issues with the previous fix.
The first was the case where the pragma types were interchanging, like:
{-# OPTIONS_GHC ... #-}
{-# LANGUAGE ... #-}
{-# LANGUAGE ... #-} -- newly added, should be last
{-# OPTIONS_GHC ... #-}
Here the line number for the last LANGUAGE pragma was always calculated last and used even if it wasn't the largest of the three. This is fixed now, by taking the max.
The other issue was when cleaning things up last time I changed the 'afterShebang' function to avoid some duplication, the tests didn't have a case to check for this but it worked out that when there is no Language pragma at the top of the file this would basically match any type of pragma later in the file instead of none. This is fixed now just by calculating the shebang separately to LANGUAGE and OPTIONS_GHC.
I added a bunch of new tests too just for different types of interchanging and ignoring later pragmas like the BangPatterns example in the original issue.