GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T18:04:36Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/15471Polymorphism, typed splices and type inference don't mix2019-07-07T18:04:36ZMatthew PickeringPolymorphism, typed splices and type inference don't mixTrying to quote and splice a polymorphic function doesn't work unless you have a type signature.
```
{-# LANGUAGE TemplateHaskell #-}
module A where
foo1 x = x
test_foo = [|| foo1 ||]
```
```
{-# LANGUAGE TemplateHaskell #-}
module B...Trying to quote and splice a polymorphic function doesn't work unless you have a type signature.
```
{-# LANGUAGE TemplateHaskell #-}
module A where
foo1 x = x
test_foo = [|| foo1 ||]
```
```
{-# LANGUAGE TemplateHaskell #-}
module B where
import A
qux = $$(test_foo)
```
The type of `qux` is `Any -> Any`! Which is clearly wrong.
Adding a type signature to `qux` fixes the problem.
```
qux :: a -> a
qux = $$(test_foo)
```
Either there should be a better error or this should just work.
It seems that this has always been broken. Ryan tested on GHC 7.8.4 for me.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Polymorphism, typed splices and type inference don't mix","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Trying to quote and splice a polymorphic function doesn't work unless you have a type signature.\r\n\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\nmodule A where\r\n\r\nfoo1 x = x\r\n\r\ntest_foo = [|| foo1 ||]\r\n}}}\r\n\r\n{{{\r\n{-# LANGUAGE TemplateHaskell #-}\r\nmodule B where\r\n\r\nimport A\r\n\r\nqux = $$(test_foo)\r\n}}}\r\n\r\nThe type of `qux` is `Any -> Any`! Which is clearly wrong.\r\n\r\nAdding a type signature to `qux` fixes the problem.\r\n\r\n{{{\r\nqux :: a -> a\r\nqux = $$(test_foo)\r\n}}}\r\n\r\nEither there should be a better error or this should just work.\r\n\r\nIt seems that this has always been broken. Ryan tested on GHC 7.8.4 for me.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/16195Program with trivial polymorphism leads to out of scope dictionary2019-07-07T18:01:00ZMatthew PickeringProgram with trivial polymorphism leads to out of scope dictionaryAlmost certainly due to c2455e647501c5a382861196b64df3dd05b620a2
A trivial program now causes a core lint error due to an out-of-scope dictionary.
```
module A where
foo :: Code (IO ())
foo = [|| return () ||]
```
```
module B where
...Almost certainly due to c2455e647501c5a382861196b64df3dd05b620a2
A trivial program now causes a core lint error due to an out-of-scope dictionary.
```
module A where
foo :: Code (IO ())
foo = [|| return () ||]
```
```
module B where
main :: IO ()
main = $$foo
```
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
In the expression: return @ IO $dMonad_a4od @ () ()
Out of scope: $dMonad_a4od :: Monad m_a4oc[tau:0]
[LclId]
*** Offending Program ***
Rec {
$trModule :: Module
[LclIdX]
$trModule = Module (TrNameS "main"#) (TrNameS "B"#)
main :: IO ()
[LclIdX]
main = return @ IO $dMonad_a4od @ () ()
end Rec }
*** End of Offense ***
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.7 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Program with trivial polymorphism leads to out of scope dictionary","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.7","keywords":["TypedTemplateHaskell"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Almost certainly due to c2455e647501c5a382861196b64df3dd05b620a2\r\n\r\nA trivial program now causes a core lint error due to an out-of-scope dictionary. \r\n\r\n{{{\r\nmodule A where\r\n\r\nfoo :: Code (IO ())\r\nfoo = [|| return () ||]\r\n}}}\r\n\r\n{{{\r\nmodule B where\r\n\r\nmain :: IO ()\r\nmain = $$foo\r\n}}}\r\n\r\n{{{\r\n*** Core Lint errors : in result of Desugar (before optimization) ***\r\n<no location info>: warning:\r\n In the expression: return @ IO $dMonad_a4od @ () ()\r\n Out of scope: $dMonad_a4od :: Monad m_a4oc[tau:0]\r\n [LclId]\r\n*** Offending Program ***\r\nRec {\r\n$trModule :: Module\r\n[LclIdX]\r\n$trModule = Module (TrNameS \"main\"#) (TrNameS \"B\"#)\r\n\r\nmain :: IO ()\r\n[LclIdX]\r\nmain = return @ IO $dMonad_a4od @ () ()\r\nend Rec }\r\n\r\n*** End of Offense ***\r\n}}}\r\n\r\n","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1