Failing on top level template haskell splices #70

Closed
opened 2017-11-29 00:49:49 +01:00 by eborden · 3 comments
eborden commented 2017-11-29 00:49:49 +01:00 (Migrated from github.com)

For some reason brittany is failing to print exact for top level
splices. This may be an issue in brittany or ghc-exact-print, I'm
not sure. I've added failing tests to highlight this issue. This bug
causes brittany to produce syntactically invalid Haskell.

1) template haskell top level splice
      expected: Right
                {-# LANGUAGE TemplateHaskell #-}
                deriveFromJSON (unPrefix "assignPost") ''AssignmentPost

      but got: Right
                {-# LANGUAGE TemplateHaskell #-}
                deriveFromJSON (unPrefix "assignPost") ''
For some reason `brittany` is failing to print exact for top level splices. This may be an issue in `brittany` or `ghc-exact-print`, I'm not sure. I've added failing tests to highlight this issue. This bug causes `brittany` to produce syntactically invalid Haskell. ``` 1) template haskell top level splice expected: Right {-# LANGUAGE TemplateHaskell #-} deriveFromJSON (unPrefix "assignPost") ''AssignmentPost but got: Right {-# LANGUAGE TemplateHaskell #-} deriveFromJSON (unPrefix "assignPost") '' ```
lspitzner commented 2017-12-08 19:34:25 +01:00 (Migrated from github.com)

I have found the cause of this. The filtering of annotations per top-level decl throws away one annotation connected to the Unqual identifier that is in ''AssignmentPost. I am a bit confused that this part of the syntax tree even has an Annotation, because it cannot have an AnnKey.

I'll investigate this a bit more; however there already would be a brute-force fix: Don't filter annotation for externally-printed top-level decls.

I have found the cause of this. The filtering of annotations per top-level decl throws away one annotation connected to the `Unqual` identifier that is in `''AssignmentPost`. I am a bit confused that this part of the syntax tree even _has_ an Annotation, because it cannot have an AnnKey. I'll investigate this a bit more; however there already would be a brute-force fix: Don't filter annotation for externally-printed top-level decls.
eborden commented 2017-12-08 20:02:10 +01:00 (Migrated from github.com)

Oh awesome. I was just trying to repro this in ghc-exactprint the other night. 🎉

Oh awesome. I was just trying to repro this in `ghc-exactprint` the other night. :tada:
lspitzner commented 2017-12-08 20:04:18 +01:00 (Migrated from github.com)

Should be fixed. In theory this fix is a bit sloppy because we should calculate some transitive closure in extractToplevelAnns. But as rarely as annCapturedSpan seems to be used, I'll take that risk.

Should be fixed. In theory this fix is a bit sloppy because we should calculate some transitive closure in `extractToplevelAnns`. But as rarely as `annCapturedSpan` seems to be used, I'll take that risk.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hexagoxel/brittany#70
There is no content yet.