GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:32:42Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/11004hsc2hs does not handle single quotes properly2019-07-07T18:32:42ZSergey Vinokurovhsc2hs does not handle single quotes properlyThe tool gets confused by quotes for promoted constructors (https://downloads.haskell.org/\~ghc/latest/docs/html/users_guide/promotion.html\#promotion-syntax). Here's an example:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #...The tool gets confused by quotes for promoted constructors (https://downloads.haskell.org/\~ghc/latest/docs/html/users_guide/promotion.html\#promotion-syntax). Here's an example:
```hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
data Foo = Foo | Bar
data Indexed ix where
Indexed :: Indexed 'Foo
main :: IO ()
main = print $ #size int
```
gets translated into
```hs
{-# LINE 1 "Test.hsc" #-}
{-# LANGUAGE DataKinds #-}
{-# LINE 2 "Test.hsc" #-}
{-# LANGUAGE GADTs #-}
data Foo = Foo | Bar
data Indexed ix where
Indexed :: Indexed 'Foo
main :: IO ()
main = print $ #size int
```
Then GHC complains about `#size`:
```
Test.hsc:10:16: parse error on input ‘#’
```
Judging from the source of utils/hsc2hs/HSCParser.hs, the tool treats single quotes the same way as double quotes. I.e. it looks for balanced, possibly multiline, strings delimited by '. At least, it seems unnecessary to expect newlines in that string-like structure, because character literals cannot contain newlines, AFAIK.
It's interesting to note that this problem looks like a bit of an edge case, since highlighting in the ticket seems to be confused as well.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | hsc2hs |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"hsc2hs does not handle single quotes properly","status":"New","operating_system":"","component":"hsc2hs","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.10.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The tool gets confused by quotes for promoted constructors (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/promotion.html#promotion-syntax). Here's an example:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LANGUAGE GADTs #-}\r\n\r\ndata Foo = Foo | Bar\r\n\r\ndata Indexed ix where\r\n Indexed :: Indexed 'Foo\r\n\r\nmain :: IO ()\r\nmain = print $ #size int\r\n}}}\r\n\r\ngets translated into\r\n\r\n{{{#!hs\r\n{-# LINE 1 \"Test.hsc\" #-}\r\n{-# LANGUAGE DataKinds #-}\r\n{-# LINE 2 \"Test.hsc\" #-}\r\n{-# LANGUAGE GADTs #-}\r\n\r\ndata Foo = Foo | Bar\r\n\r\ndata Indexed ix where\r\n Indexed :: Indexed 'Foo\r\n\r\nmain :: IO ()\r\nmain = print $ #size int\r\n}}}\r\n\r\nThen GHC complains about `#size`:\r\n\r\n{{{\r\nTest.hsc:10:16: parse error on input ‘#’\r\n}}}\r\n\r\nJudging from the source of utils/hsc2hs/HSCParser.hs, the tool treats single quotes the same way as double quotes. I.e. it looks for balanced, possibly multiline, strings delimited by '. At least, it seems unnecessary to expect newlines in that string-like structure, because character literals cannot contain newlines, AFAIK.\r\n\r\nIt's interesting to note that this problem looks like a bit of an edge case, since highlighting in the ticket seems to be confused as well.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Travis Whitakerpi.boy.travis@gmail.comTravis Whitakerpi.boy.travis@gmail.com