Support promoted type applications. #376

Open
ChickenProp wants to merge 1 commits from ChickenProp/promoted-type-applications into master
ChickenProp commented 2022-11-01 14:21:52 +01:00 (Migrated from github.com)

Closes #370.

Up to GHC 8.10,

foo @ 'Bar

was a valid type application. In GHC 9 it's not, which means brittany needs to allow

foo @'Bar

which it now does.

The reason the space was needed was to allow a promoted type variable at the head of a type-level list. That is,

'['Foo]

is invalid syntax, because it initially parses as the character '['. So the promoted type variable was always given a separator at the beginning, and we'd get

'[ 'Foo]

which was valid. Now we handle this case by specifically examining the head of a type-level list; if it's promoted we introduce spaces, so

'[ 'Foo ]
'[Foo]

I've added tests for this and some related cases. In doing so I noticed that unnecessary spaces get added in front of commas in these lists; I believe that's a separate bug, and I've written a comment explaining why it happens, but I haven't tried to fix it.

I'm not sure when the first alternates in the FirstLastSingleton and FirstLast branches would ever be hit, so I'm not entirely sure if the separators are necessary there. But since docSeparator disappears at the end of a line and merges with adjacent separators, they should be harmless.

Closes #370. Up to GHC 8.10, foo @ 'Bar was a valid type application. In GHC 9 it's not, which means brittany needs to allow foo @'Bar which it now does. The reason the space was needed was to allow a promoted type variable at the head of a type-level list. That is, '['Foo] is invalid syntax, because it initially parses as the character `'['`. So the promoted type variable was always given a separator at the beginning, and we'd get '[ 'Foo] which was valid. Now we handle this case by specifically examining the head of a type-level list; if it's promoted we introduce spaces, so '[ 'Foo ] '[Foo] I've added tests for this and some related cases. In doing so I noticed that unnecessary spaces get added in front of commas in these lists; I believe that's a separate bug, and I've written a comment explaining why it happens, but I haven't tried to fix it. I'm not sure when the first alternates in the `FirstLastSingleton` and `FirstLast` branches would ever be hit, so I'm not entirely sure if the separators are necessary there. But since `docSeparator` disappears at the end of a line and merges with adjacent separators, they should be harmless.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b ChickenProp/promoted-type-applications master
git pull origin ChickenProp/promoted-type-applications

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff ChickenProp/promoted-type-applications
git push origin master
Sign in to join this conversation.
There is no content yet.