GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-07-04T14:57:55Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/13064Incorrect redudant imports warning2023-07-04T14:57:55ZOleg GrenrusIncorrect redudant imports warningWith a simple package:
issue.cabal:
```
name: issue
version: 0
cabal-version: >= 1.10
build-type: Simple
library
build-depends: base, binary, binary-orphans==0.1.5.2
exposed-modules: Issue
```
Issue.hs:
```
{-# LANGUAGE DeriveGe...With a simple package:
issue.cabal:
```
name: issue
version: 0
cabal-version: >= 1.10
build-type: Simple
library
build-depends: base, binary, binary-orphans==0.1.5.2
exposed-modules: Issue
```
Issue.hs:
```
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -Wall #-}
module Issue (T (..)) where
import Prelude ()
import Data.Binary.Orphans
import Data.Binary (Binary (..))
import GHC.Generics (Generic)
import Data.Aeson (Value)
data T = T Value deriving (Generic)
instance Binary T
```
GHC 7.10.3 correctly reports:
```
Issue.hs:7:1: Warning:
The import of ‘Data.Binary’ is redundant
except perhaps to import instances from ‘Data.Binary’
To import instances alone, use: import Data.Binary()
```
GHC 8.0.1 incorrectly (!!!) reports:
```
Issue.hs:6:1: warning: [-Wunused-imports]
The import of ‘Data.Binary.Orphans’ is redundant
except perhaps to import instances from ‘Data.Binary.Orphans’
To import instances alone, use: import Data.Binary.Orphans(
```
but `Binary Value` instance is imported from `Data.Binary.Orphans`.
---
In real life while compiling https://github.com/futurice/haskell-mega-repo/blob/93c3f111f39c973769c35725d90c9b8ef9a57de3/futurice-github/src/Futurice/GitHub.hs the `Data.Binary` redundant import isn't reported, as `Futurice.Prelude` exports other stuff, which is used. See https://gist.github.com/phadej/bb26df19c611260ab8f867729def39b9 for minimal imports reported with `-ddump-minimal-imports`.
\#\# Status
I've submitted some PRs to fix the impending unused import warnings:
- MERGED https://github.com/haskell/cabal/pull/5673
- MERGED https://github.com/kolmodin/binary/pull/159
- MERGED https://github.com/haskell/bytestring/pull/168
- MERGED https://github.com/haskell/containers/pull/576
- MERGED https://github.com/haskell/text/pull/240
I've also added a new ghc patch here:
- MERGED https://phabricator.haskell.org/D53128.8.1davidedavidehttps://gitlab.haskell.org/ghc/ghc/-/issues/13862Optional "-v" not allowed with :load in GHCi2019-07-07T18:19:47ZvantoOptional "-v" not allowed with :load in GHCiWhen loading a file in GHCi with the command `:load` and the file must import another file, if that other file is unavailable then GHCi sends the following error\\\\
```
Failed to load interface for `xxx`
Use -v to see a list of the fil...When loading a file in GHCi with the command `:load` and the file must import another file, if that other file is unavailable then GHCi sends the following error\\\\
```
Failed to load interface for `xxx`
Use -v to see a list of the files searched for.
```
' xxx ' is the name of the imported file that GHCi cannot find.\\\\
But we can not use a flag ( ie -v) with the command `:load` in GHCi.\\\\
This error is not appropriate in GHCi when using `:load`
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | GHCi |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Optional \"-v\" not allowed with :load in GHCi","status":"New","operating_system":"","component":"GHCi","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When loading a file in GHCi with the command {{{:load}}} and the file must import another file, if that other file is unavailable then GHCi sends the following error\\\\\r\n\r\n{{{\r\nFailed to load interface for `xxx`\r\nUse -v to see a list of the files searched for.\r\n}}}\r\n' xxx ' is the name of the imported file that GHCi cannot find.\\\\\r\nBut we can not use a flag ( ie -v) with the command {{{:load}}} in GHCi.\\\\\r\nThis error is not appropriate in GHCi when using {{{:load}}}\r\n","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Roland SennRoland Sennhttps://gitlab.haskell.org/ghc/ghc/-/issues/14230Gruesome kind mismatch errors for associated data family instances2019-07-07T18:17:51ZRyan ScottGruesome kind mismatch errors for associated data family instancesSpun off from #14175\##14230. This program, which can only really be compiled on GHC HEAD at the moment:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
...Spun off from #14175\##14230. This program, which can only really be compiled on GHC HEAD at the moment:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where
class C k where
data CD :: k -> k -> *
instance C (Maybe a) where
data CD :: (k -> *) -> (k -> *) -> *
```
Gives a heinous error message:
```
Bug.hs:11:3: error:
• Expected kind ‘(k -> *) -> (k -> *) -> *’,
but ‘CD :: (k -> *) -> (k -> *) -> *’ has kind ‘Maybe a
-> Maybe a -> *’
• In the data instance declaration for ‘CD’
In the instance declaration for ‘C (Maybe a)’
|
11 | data CD :: (k -> *) -> (k -> *) -> *
| ^^^^^^^
```
- We shouldn't be expecting kind `(k -> *) -> (k -> *) -> *`, but rather kind `Maybe a -> Maybe a -> *`, due to the instance head itself.
- The phrase `‘CD :: (k -> *) -> (k -> *) -> *’ has kind ‘Maybe -> Maybe a -> *’` is similarly confusing. This doesn't point out that the real issue is the use of `(k -> *)`.
Another program in a similar vein:
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
class C a where
data CD k (a :: k) :: k -> *
instance C (Maybe a) where
data CD k (a :: k -> *) :: (k -> *) -> *
```
```
Bug.hs:13:3: error:
• Expected kind ‘(k -> *) -> *’,
but ‘CD k (a :: k -> *) :: (k -> *) -> *’ has kind ‘k -> *’
• In the data instance declaration for ‘CD’
In the instance declaration for ‘C (Maybe a)’
|
13 | data CD k (a :: k -> *) :: (k -> *) -> *
| ^^^^^^^^^^^^^^^^^^^^^^^
```
This error message is further muddled by the incorrect use of `k` as the first type pattern (instead of `k -> *`, as subsequent kind signatures would suggest).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Gruesome kind mismatch errors for associated data family instances","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Spun off from https://ghc.haskell.org/trac/ghc/ticket/14175#comment:9. This program, which can only really be compiled on GHC HEAD at the moment:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE PolyKinds #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule Bug where\r\n\r\nclass C k where\r\n data CD :: k -> k -> *\r\n\r\ninstance C (Maybe a) where\r\n data CD :: (k -> *) -> (k -> *) -> *\r\n}}}\r\n\r\nGives a heinous error message:\r\n\r\n{{{\r\nBug.hs:11:3: error:\r\n • Expected kind ‘(k -> *) -> (k -> *) -> *’,\r\n but ‘CD :: (k -> *) -> (k -> *) -> *’ has kind ‘Maybe a\r\n -> Maybe a -> *’\r\n • In the data instance declaration for ‘CD’\r\n In the instance declaration for ‘C (Maybe a)’\r\n |\r\n11 | data CD :: (k -> *) -> (k -> *) -> *\r\n | ^^^^^^^\r\n}}}\r\n\r\n* We shouldn't be expecting kind `(k -> *) -> (k -> *) -> *`, but rather kind `Maybe a -> Maybe a -> *`, due to the instance head itself.\r\n* The phrase `‘CD :: (k -> *) -> (k -> *) -> *’ has kind ‘Maybe -> Maybe a -> *’` is similarly confusing. This doesn't point out that the real issue is the use of `(k -> *)`.\r\n\r\nAnother program in a similar vein:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\n\r\nclass C a where\r\n data CD k (a :: k) :: k -> *\r\n\r\ninstance C (Maybe a) where\r\n data CD k (a :: k -> *) :: (k -> *) -> *\r\n}}}\r\n{{{\r\nBug.hs:13:3: error:\r\n • Expected kind ‘(k -> *) -> *’,\r\n but ‘CD k (a :: k -> *) :: (k -> *) -> *’ has kind ‘k -> *’\r\n • In the data instance declaration for ‘CD’\r\n In the instance declaration for ‘C (Maybe a)’\r\n |\r\n13 | data CD k (a :: k -> *) :: (k -> *) -> *\r\n | ^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}\r\n\r\nThis error message is further muddled by the incorrect use of `k` as the first type pattern (instead of `k -> *`, as subsequent kind signatures would suggest).","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1Richard Eisenbergrae@richarde.devRichard Eisenbergrae@richarde.devhttps://gitlab.haskell.org/ghc/ghc/-/issues/14813EmptyCase thinks pattern match involving type family is not exhaustive, when ...2019-07-07T18:15:28ZRyan ScottEmptyCase thinks pattern match involving type family is not exhaustive, when it actually isGHC warns on this program:
```hs
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -Wall #-}
module Bug where
import Data.Ki...GHC warns on this program:
```hs
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -Wall #-}
module Bug where
import Data.Kind
import Data.Void
data SBool (z :: Bool) where
SFalse :: SBool 'False
STrue :: SBool 'True
type family F (b :: Bool) (a :: Type) :: Type where
F 'True a = a
F 'False _ = Void
dispatch :: forall (b :: Bool) (a :: Type). SBool b -> F b a -> a
dispatch STrue x = x
dispatch SFalse x = case x of {}
```
```
$ /opt/ghc/8.2.2/bin/ghci Bug.hs
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:22:21: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: _ :: F b a
|
22 | dispatch SFalse x = case x of {}
| ^^^^
```
This warning is incorrect, as `x` is of type `F 'False a`, or `Void`, in that case alternative.
Curiously, if you ascribe either the pattern for `x`:
```hs
dispatch SFalse (x :: F 'False a) = case x of {}
```
Or the case scrutinee:
```hs
dispatch SFalse x = case x :: F 'False a of {}
```
Then the warning goes away.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.2 |
| 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":"EmptyCase thinks pattern match involving type family is not exhaustive, when it actually is","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["PatternMatchWarnings"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"GHC warns on this program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE EmptyCase #-}\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE ScopedTypeVariables #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# OPTIONS_GHC -Wall #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Void\r\n\r\ndata SBool (z :: Bool) where\r\n SFalse :: SBool 'False\r\n STrue :: SBool 'True\r\n\r\ntype family F (b :: Bool) (a :: Type) :: Type where\r\n F 'True a = a\r\n F 'False _ = Void\r\n\r\ndispatch :: forall (b :: Bool) (a :: Type). SBool b -> F b a -> a\r\ndispatch STrue x = x\r\ndispatch SFalse x = case x of {}\r\n}}}\r\n\r\n{{{\r\n$ /opt/ghc/8.2.2/bin/ghci Bug.hs\r\nGHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Bug ( Bug.hs, interpreted )\r\n\r\nBug.hs:22:21: warning: [-Wincomplete-patterns]\r\n Pattern match(es) are non-exhaustive\r\n In a case alternative: Patterns not matched: _ :: F b a\r\n |\r\n22 | dispatch SFalse x = case x of {}\r\n | ^^^^\r\n}}}\r\n\r\nThis warning is incorrect, as `x` is of type `F 'False a`, or `Void`, in that case alternative.\r\n\r\nCuriously, if you ascribe either the pattern for `x`:\r\n\r\n{{{#!hs\r\ndispatch SFalse (x :: F 'False a) = case x of {}\r\n}}}\r\n\r\nOr the case scrutinee:\r\n\r\n{{{#!hs\r\ndispatch SFalse x = case x :: F 'False a of {}\r\n}}}\r\n\r\nThen the warning goes away.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15305Erroneous "non-exhaustive pattern match" using nested GADT with strictness an...2020-09-22T13:41:25ZjkoppelErroneous "non-exhaustive pattern match" using nested GADT with strictness annotationIn the following code, `fun` contains an exhaustive pattern match, but, when compiling with -Wall, ghc erroneously reports a non-exhaustive pattern match.
```hs
data (:+:) f g a = Inl !(f a) | Inr !(g a)
data A
data B
data Foo l where...In the following code, `fun` contains an exhaustive pattern match, but, when compiling with -Wall, ghc erroneously reports a non-exhaustive pattern match.
```hs
data (:+:) f g a = Inl !(f a) | Inr !(g a)
data A
data B
data Foo l where
Foo :: Foo A
data Bar l where
Bar :: Bar B
type Sig = Foo :+: Bar
fun :: Sig B -> Int
fun (Inr Bar) = 1
```
This report came from https://stackoverflow.com/questions/16225281/gadts-failed-exhaustiveness-checking . Without strictness annotations, this is indeed a failed exhaustive check, due to bottom. I spoke to Richard Eisenberg at PLDI a few days ago, and he informed me that, if this warning did not disappear with strictness annotations, it was a bug. I added strictness annotations, and it did not disappear. I've tried all combinations of using strictness annotations and/or running with `{-# LANGUAGE Strict #-}`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Erroneous \"non-exhaustive pattern match\" using nested GADT with strictness annotation","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"In the following code, `fun` contains an exhaustive pattern match, but, when compiling with -Wall, ghc erroneously reports a non-exhaustive pattern match.\r\n\r\n{{{#!hs\r\n\r\ndata (:+:) f g a = Inl !(f a) | Inr !(g a)\r\n\r\ndata A\r\ndata B\r\n\r\ndata Foo l where\r\n Foo :: Foo A\r\n\r\ndata Bar l where\r\n Bar :: Bar B\r\n\r\ntype Sig = Foo :+: Bar\r\n\r\nfun :: Sig B -> Int\r\nfun (Inr Bar) = 1\r\n\r\n}}}\r\n\r\nThis report came from https://stackoverflow.com/questions/16225281/gadts-failed-exhaustiveness-checking . Without strictness annotations, this is indeed a failed exhaustive check, due to bottom. I spoke to Richard Eisenberg at PLDI a few days ago, and he informed me that, if this warning did not disappear with strictness annotations, it was a bug. I added strictness annotations, and it did not disappear. I've tried all combinations of using strictness annotations and/or running with `{-# LANGUAGE Strict #-}`.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15330Error message prints invisible kind arguments in a visible matter2019-07-07T18:13:08ZRyan ScottError message prints invisible kind arguments in a visible matterConsider the following program:
```hs
{-# LANGUAGE RankNTypes #-} ...Consider the following program:
```hs
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
data T :: forall a. a -> Type
f1 :: Proxy (T True)
f1 = "foo"
f2 :: forall (t :: forall a. a -> Type).
Proxy (t True)
f2 = "foo"
```
This program doesn't typecheck (for good reason). The error messages, however, are a bit iffy:
```
$ /opt/ghc/8.4.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:11:6: error:
• Couldn't match expected type ‘Proxy (T 'True)’
with actual type ‘[Char]’
• In the expression: "foo"
In an equation for ‘f1’: f1 = "foo"
|
11 | f1 = "foo"
| ^^^^^
Bug.hs:15:6: error:
• Couldn't match expected type ‘Proxy (t Bool 'True)’
with actual type ‘[Char]’
• In the expression: "foo"
In an equation for ‘f2’: f2 = "foo"
• Relevant bindings include
f2 :: Proxy (t Bool 'True) (bound at Bug.hs:15:1)
|
15 | f2 = "foo"
| ^^^^^
```
Note that in the error message for `f1`, the type `T 'True` is printed correctly—the invisible `Bool` argument is omitted. However, in the error message for `f2`, this is not the case, as the type `t Bool 'True` is printed. That `Bool` is an invisible argument as well, and should not be printed without the use of, say, `-fprint-explicit-kinds`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Error message prints invisible kind arguments in a visible matter","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":["TypeInType"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Consider the following program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE RankNTypes #-} \r\n{-# LANGUAGE TypeInType #-} \r\nmodule Bug where \r\n \r\nimport Data.Kind \r\nimport Data.Proxy \r\n \r\ndata T :: forall a. a -> Type \r\n \r\nf1 :: Proxy (T True)\r\nf1 = \"foo\"\r\n\r\nf2 :: forall (t :: forall a. a -> Type).\r\n Proxy (t True)\r\nf2 = \"foo\"\r\n}}}\r\n\r\nThis program doesn't typecheck (for good reason). The error messages, however, are a bit iffy:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:11:6: error:\r\n • Couldn't match expected type ‘Proxy (T 'True)’\r\n with actual type ‘[Char]’\r\n • In the expression: \"foo\"\r\n In an equation for ‘f1’: f1 = \"foo\"\r\n |\r\n11 | f1 = \"foo\"\r\n | ^^^^^\r\n\r\nBug.hs:15:6: error:\r\n • Couldn't match expected type ‘Proxy (t Bool 'True)’\r\n with actual type ‘[Char]’\r\n • In the expression: \"foo\"\r\n In an equation for ‘f2’: f2 = \"foo\"\r\n • Relevant bindings include\r\n f2 :: Proxy (t Bool 'True) (bound at Bug.hs:15:1)\r\n |\r\n15 | f2 = \"foo\"\r\n | ^^^^^\r\n}}}\r\n\r\nNote that in the error message for `f1`, the type `T 'True` is printed correctly—the invisible `Bool` argument is omitted. However, in the error message for `f2`, this is not the case, as the type `t Bool 'True` is printed. That `Bool` is an invisible argument as well, and should not be printed without the use of, say, `-fprint-explicit-kinds`.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15515Bogus "No instance" error when type families appear in kinds2019-07-07T18:04:23ZRyan ScottBogus "No instance" error when type families appear in kindsThe following code typechecks:
```hs
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
class C a where
c :: Proxy a
type family F
data D...The following code typechecks:
```hs
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module Bug where
import Data.Kind
import Data.Proxy
class C a where
c :: Proxy a
type family F
data D :: F -> Type
instance C (D :: F -> Type) where
c = undefined
```
However, if we try to actually //use// that `C D` instance, like so:
```hs
c' :: Proxy (D :: F -> Type)
c' = c @(D :: F -> Type)
```
Then GHC gives a rather flummoxing error message:
```
$ /opt/ghc/8.4.3/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:20:6: error:
• No instance for (C D) arising from a use of ‘c’
• In the expression: c @(D :: F -> Type)
In an equation for ‘c'’: c' = c @(D :: F -> Type)
|
20 | c' = c @(D :: F -> Type)
| ^^^^^^^^^^^^^^^^^^^
```
But that error is clearly misleading, as we defined such a `C D` instance directly above it!
The use of the type family `F` in the kind of `D` appears to play an important role in this bug. If I change `F` to be a data type (e.g., `data F`), then `c'` is accepted.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Bogus \"No instance\" error when type families appear in kinds","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":["TypeFamilies","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following code typechecks:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeApplications #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeInType #-}\r\nmodule Bug where\r\n\r\nimport Data.Kind\r\nimport Data.Proxy\r\n\r\nclass C a where\r\n c :: Proxy a\r\n\r\ntype family F\r\n\r\ndata D :: F -> Type\r\n\r\ninstance C (D :: F -> Type) where\r\n c = undefined\r\n}}}\r\n\r\nHowever, if we try to actually //use// that `C D` instance, like so:\r\n\r\n{{{#!hs\r\nc' :: Proxy (D :: F -> Type)\r\nc' = c @(D :: F -> Type)\r\n}}}\r\n\r\nThen GHC gives a rather flummoxing error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.3/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:20:6: error:\r\n • No instance for (C D) arising from a use of ‘c’\r\n • In the expression: c @(D :: F -> Type)\r\n In an equation for ‘c'’: c' = c @(D :: F -> Type)\r\n |\r\n20 | c' = c @(D :: F -> Type)\r\n | ^^^^^^^^^^^^^^^^^^^\r\n}}}\r\n\r\nBut that error is clearly misleading, as we defined such a `C D` instance directly above it!\r\n\r\nThe use of the type family `F` in the kind of `D` appears to play an important role in this bug. If I change `F` to be a data type (e.g., `data F`), then `c'` is accepted.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15584nonVoid is too conservative w.r.t. strict argument types2019-07-07T18:04:01ZRyan ScottnonVoid is too conservative w.r.t. strict argument typesIn the implementation of the pattern-match coverage checker, the `nonVoid` function checks is some `Type` is inhabitable by at least one constructor. However, `nonVoid` currently does not recursively call itself on the strict argument ty...In the implementation of the pattern-match coverage checker, the `nonVoid` function checks is some `Type` is inhabitable by at least one constructor. However, `nonVoid` currently does not recursively call itself on the strict argument types of each constructor that is considered. This means that certain exhaustive functions are mistakenly flagged as non-exhaustive, such as in the following example:
```hs
{-# LANGUAGE EmptyCase #-}
{-# OPTIONS -Wincomplete-patterns #-}
module Bug where
import Data.Void
data V = MkV !Void
data S = MkS !V
f :: S -> a
f x = case x of {}
```
```
$ /opt/ghc/head/bin/ghci Bug.hs
GHCi, version 8.7.20180827: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug ( Bug.hs, interpreted )
Bug.hs:11:7: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative: Patterns not matched: (MkS _)
|
11 | f x = case x of {}
| ^^^^^^^^^^^^
```
The natural solution would be to call `nonVoid` recursively on strict argument types, so as to be able to tell that `S` in uninhabitable. But we can't just do this willy nilly, since we could run into infinite loops with recursive examples like this one:
```hs
data Abyss = MkAbyss !Abyss
stareIntoTheAbyss :: Abyss -> a
stareIntoTheAbyss x = case x of {}
```
Better solution: put a recursive type checker into `nonVoid`, and bail out if recursion is detected.
Patch incoming.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.5 |
| 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":"nonVoid is too conservative w.r.t. strict argument types","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.5","keywords":["PatternMatchWarnings"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"In the implementation of the pattern-match coverage checker, the `nonVoid` function checks is some `Type` is inhabitable by at least one constructor. However, `nonVoid` currently does not recursively call itself on the strict argument types of each constructor that is considered. This means that certain exhaustive functions are mistakenly flagged as non-exhaustive, such as in the following example:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE EmptyCase #-}\r\n{-# OPTIONS -Wincomplete-patterns #-}\r\nmodule Bug where\r\n\r\nimport Data.Void\r\n\r\ndata V = MkV !Void\r\ndata S = MkS !V\r\n\r\nf :: S -> a\r\nf x = case x of {}\r\n}}}\r\n{{{\r\n$ /opt/ghc/head/bin/ghci Bug.hs\r\nGHCi, version 8.7.20180827: http://www.haskell.org/ghc/ :? for help\r\nLoaded GHCi configuration from /home/rgscott/.ghci\r\n[1 of 1] Compiling Bug ( Bug.hs, interpreted )\r\n\r\nBug.hs:11:7: warning: [-Wincomplete-patterns]\r\n Pattern match(es) are non-exhaustive\r\n In a case alternative: Patterns not matched: (MkS _)\r\n |\r\n11 | f x = case x of {}\r\n | ^^^^^^^^^^^^\r\n}}}\r\n\r\nThe natural solution would be to call `nonVoid` recursively on strict argument types, so as to be able to tell that `S` in uninhabitable. But we can't just do this willy nilly, since we could run into infinite loops with recursive examples like this one:\r\n\r\n{{{#!hs\r\ndata Abyss = MkAbyss !Abyss\r\n\r\nstareIntoTheAbyss :: Abyss -> a\r\nstareIntoTheAbyss x = case x of {}\r\n}}}\r\n\r\nBetter solution: put a recursive type checker into `nonVoid`, and bail out if recursion is detected.\r\n\r\nPatch incoming.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15659Wacky error message when RULE mentions out-of-scope variable2019-07-07T18:03:33ZRyan ScottWacky error message when RULE mentions out-of-scope variableIf I compile the following program with GHC 8.4 or later:
```hs
module Foo where
{-# RULES "test" forall x. f x = x #-}
```
The error message I get is somewhat eyebrow-raising:
```
$ /opt/ghc/8.4.3/bin/ghc Foo.hs
[1 of 1] Compiling F...If I compile the following program with GHC 8.4 or later:
```hs
module Foo where
{-# RULES "test" forall x. f x = x #-}
```
The error message I get is somewhat eyebrow-raising:
```
$ /opt/ghc/8.4.3/bin/ghc Foo.hs
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:3:11: error:
Rule "test":
Not in scope: OutOfScope(f)
in left-hand side: f x
LHS must be of form (f e1 .. en) where f is not forall'd
|
3 | {-# RULES "test" forall x. f x = x #-}
| ^^^^^^^^^^^^^^^^^^^^^^^^
```
I'm not sure what this `OutOfScope` business is, but I doubt we want to be referring to it in error messages. The error in GHC 8.2 and earlier was much less confusing:
```
$ /opt/ghc/8.2.2/bin/ghc Foo.hs
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:3:11: error:
Rule "test":
Not in scope: f
in left-hand side: f x
LHS must be of form (f e1 .. en) where f is not forall'd
|
3 | {-# RULES "test" forall x. f x = x #-}
| ^^^^^^^^^^^^^^^^^^^^^^^^
```
<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":"Wacky error message when RULE mentions out-of-scope variable","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":["newcomer"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"If I compile the following program with GHC 8.4 or later:\r\n\r\n{{{#!hs\r\nmodule Foo where\r\n\r\n{-# RULES \"test\" forall x. f x = x #-}\r\n}}}\r\n\r\nThe error message I get is somewhat eyebrow-raising:\r\n\r\n{{{\r\n$ /opt/ghc/8.4.3/bin/ghc Foo.hs\r\n[1 of 1] Compiling Foo ( Foo.hs, Foo.o )\r\n\r\nFoo.hs:3:11: error:\r\n Rule \"test\":\r\n Not in scope: OutOfScope(f)\r\n in left-hand side: f x\r\n LHS must be of form (f e1 .. en) where f is not forall'd\r\n |\r\n3 | {-# RULES \"test\" forall x. f x = x #-}\r\n | ^^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}\r\n\r\nI'm not sure what this `OutOfScope` business is, but I doubt we want to be referring to it in error messages. The error in GHC 8.2 and earlier was much less confusing:\r\n\r\n{{{\r\n$ /opt/ghc/8.2.2/bin/ghc Foo.hs\r\n[1 of 1] Compiling Foo ( Foo.hs, Foo.o )\r\n\r\nFoo.hs:3:11: error:\r\n Rule \"test\":\r\n Not in scope: f\r\n in left-hand side: f x\r\n LHS must be of form (f e1 .. en) where f is not forall'd\r\n |\r\n3 | {-# RULES \"test\" forall x. f x = x #-}\r\n | ^^^^^^^^^^^^^^^^^^^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15702"-main-is" flag is broken for recent ghc-head2019-07-07T18:03:22ZCheng Shao"-main-is" flag is broken for recent ghc-headHere is a minimal reproduction:
Main.hs:
```
main :: IO ()
main = putStrLn "Main"
```
Main2.hs:
```
module Main2 where
import Main
main2 :: IO ()
main2 = do
putStrLn "Main2"
main
```
Run ghc with something like `/home/terrorja...Here is a minimal reproduction:
Main.hs:
```
main :: IO ()
main = putStrLn "Main"
```
Main2.hs:
```
module Main2 where
import Main
main2 :: IO ()
main2 = do
putStrLn "Main2"
main
```
Run ghc with something like `/home/terrorjack/.stack/programs/x86_64-linux/ghc-8.7.20181003/bin/ghc -main-is Main2.main2 Main.hs Main2.hs`, and it reports the following error:
```
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:1:1: error:
Not in scope: ‘main2’
Perhaps you meant ‘main’ (line 2)
|
1 | main :: IO ()
| ^
```
Meanwhile, the exact same flags work for ghc-8.6.1, and also a previous ghc-head build on d90946cea1357d3e99805c27dab1e811785a4088, so some accidental breakage might be in a recent commit.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.6.1 |
| 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":"\"-main-is\" flag is broken for recent ghc-head","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Here is a minimal reproduction:\r\n\r\nMain.hs:\r\n\r\n{{{\r\nmain :: IO ()\r\nmain = putStrLn \"Main\"\r\n}}}\r\n\r\nMain2.hs:\r\n\r\n{{{\r\nmodule Main2 where\r\n\r\nimport Main\r\n\r\nmain2 :: IO ()\r\nmain2 = do\r\n putStrLn \"Main2\"\r\n main\r\n}}}\r\n\r\nRun ghc with something like `/home/terrorjack/.stack/programs/x86_64-linux/ghc-8.7.20181003/bin/ghc -main-is Main2.main2 Main.hs Main2.hs`, and it reports the following error:\r\n\r\n{{{\r\n[1 of 2] Compiling Main ( Main.hs, Main.o )\r\n\r\nMain.hs:1:1: error:\r\n Not in scope: ‘main2’\r\n Perhaps you meant ‘main’ (line 2)\r\n |\r\n1 | main :: IO ()\r\n | ^\r\n}}}\r\n\r\nMeanwhile, the exact same flags work for ghc-8.6.1, and also a previous ghc-head build on d90946cea1357d3e99805c27dab1e811785a4088, so some accidental breakage might be in a recent commit.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15962Type family & typeclass interaction suppresses errors2019-07-07T18:02:16ZmadgenType family & typeclass interaction suppresses errorsThe following program despite having a hole and an undefined variable `iDontExist` \*quietly\* fails to compile on 8.4.3 and 8.4.4. It produces errors as expected on 8.6.1 and 8.6.2.
By quietly failing, I mean it fails on CLI but withou...The following program despite having a hole and an undefined variable `iDontExist` \*quietly\* fails to compile on 8.4.3 and 8.4.4. It produces errors as expected on 8.6.1 and 8.6.2.
By quietly failing, I mean it fails on CLI but without producing any error messages and in GHCI. It just says "Failed, no modules loaded."
```hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
module Bug where
import Data.Kind (Type)
type Exp a = a -> Type
type family Eval (e :: Exp a) :: a
data OpKind = Conjunction
data Dual (k :: OpKind) :: Exp OpKind
data Map :: (a -> Exp b) -> [ a ] -> Exp [ b ]
type instance Eval (Map f (a ': as)) = Eval (f a) ': Eval (Map f as)
data Big :: [ OpKind ] -> Type where
Big :: [ Big ks ] -> Big ('Conjunction ': ks)
dualBig :: Big ks -> Big (Eval (Map Dual ks))
dualBig = _
instance Semigroup (Big a) where
Big xs <> Big ys = Big (xs <> ys)
instance Monoid (Big ('Conjunction ': ks)) where
mempty = iDontExist
flatten :: Monoid (Big ks) => Big (k ': k ': ks) -> Big ks
flatten = undefined
```
Sorry, the example is a bit big but almost any change causes the errors to appear again including the `Monoid` constraint on `flatten`.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.4.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Type family & typeclass interaction suppresses errors","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"⊥","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.4.3","keywords":["error","family,","message","type","typeclass,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following program despite having a hole and an undefined variable `iDontExist` *quietly* fails to compile on 8.4.3 and 8.4.4. It produces errors as expected on 8.6.1 and 8.6.2.\r\n\r\nBy quietly failing, I mean it fails on CLI but without producing any error messages and in GHCI. It just says \"Failed, no modules loaded.\"\r\n\r\n{{{#!hs\r\n{-# LANGUAGE GADTs #-}\r\n{-# LANGUAGE TypeInType #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n{-# LANGUAGE TypeOperators #-}\r\n{-# LANGUAGE FlexibleContexts #-}\r\n{-# LANGUAGE FlexibleInstances #-}\r\n\r\nmodule Bug where\r\n\r\nimport Data.Kind (Type)\r\n\r\ntype Exp a = a -> Type\r\ntype family Eval (e :: Exp a) :: a\r\n\r\ndata OpKind = Conjunction\r\n\r\ndata Dual (k :: OpKind) :: Exp OpKind\r\n\r\ndata Map :: (a -> Exp b) -> [ a ] -> Exp [ b ]\r\n\r\ntype instance Eval (Map f (a ': as)) = Eval (f a) ': Eval (Map f as)\r\n\r\ndata Big :: [ OpKind ] -> Type where\r\n Big :: [ Big ks ] -> Big ('Conjunction ': ks)\r\n\r\ndualBig :: Big ks -> Big (Eval (Map Dual ks))\r\ndualBig = _\r\n\r\ninstance Semigroup (Big a) where\r\n Big xs <> Big ys = Big (xs <> ys)\r\n\r\ninstance Monoid (Big ('Conjunction ': ks)) where\r\n mempty = iDontExist\r\n\r\nflatten :: Monoid (Big ks) => Big (k ': k ': ks) -> Big ks\r\nflatten = undefined\r\n}}} \r\n\r\nSorry, the example is a bit big but almost any change causes the errors to appear again including the `Monoid` constraint on `flatten`.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/15986Poor error message source location reporting with unsaturated type family2019-07-07T18:02:09ZRyan ScottPoor error message source location reporting with unsaturated type familyIf you compile this program:
```hs
{-# LANGUAGE TypeFamilies #-}
module Bug where
newtype WrapChar f = MkWrapChar (f Char)
type family F a
type family T a
type instance T Int = WrapChar F
```
Then you'll get this error message:
```
$...If you compile this program:
```hs
{-# LANGUAGE TypeFamilies #-}
module Bug where
newtype WrapChar f = MkWrapChar (f Char)
type family F a
type family T a
type instance T Int = WrapChar F
```
Then you'll get this error message:
```
$ /opt/ghc/8.6.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:7:15: error:
• The type family ‘F’ should have 1 argument, but has been given none
• In the type instance declaration for ‘T’
|
7 | type instance T Int = WrapChar F
| ^
```
The thing is, the location of that caret is rather unfocused. It's pointing at `T`, but the real culprit is `F`!
I know that GHC can do better here because other error messages actually get this right. For instance, if you change the `T Int` instance to this:
```hs
type instance T Int = F
```
Then GHC will actually point to `F` in the resulting error message:
```
$ /opt/ghc/8.6.2/bin/ghc Bug.hs
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:7:23: error:
• Expecting one more argument to ‘F’
Expected a type, but ‘F’ has kind ‘* -> *’
• In the type ‘F’
In the type instance declaration for ‘T’
|
7 | type instance T Int = F
| ^
```
If GHC can point to the right place in the source code in this situation, then it ought to get the earlier situation right as well.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.6.2 |
| 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":"Poor error message source location reporting with unsaturated type family","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.8.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.2","keywords":["TypeErrors","TypeFamilies,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"If you compile this program:\r\n\r\n{{{#!hs\r\n{-# LANGUAGE TypeFamilies #-}\r\nmodule Bug where\r\n\r\nnewtype WrapChar f = MkWrapChar (f Char)\r\ntype family F a\r\ntype family T a\r\ntype instance T Int = WrapChar F\r\n}}}\r\n\r\nThen you'll get this error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.6.2/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:7:15: error:\r\n • The type family ‘F’ should have 1 argument, but has been given none\r\n • In the type instance declaration for ‘T’\r\n |\r\n7 | type instance T Int = WrapChar F\r\n | ^\r\n}}}\r\n\r\nThe thing is, the location of that caret is rather unfocused. It's pointing at `T`, but the real culprit is `F`!\r\n\r\nI know that GHC can do better here because other error messages actually get this right. For instance, if you change the `T Int` instance to this:\r\n\r\n{{{#!hs\r\ntype instance T Int = F\r\n}}}\r\n\r\nThen GHC will actually point to `F` in the resulting error message:\r\n\r\n{{{\r\n$ /opt/ghc/8.6.2/bin/ghc Bug.hs\r\n[1 of 1] Compiling Bug ( Bug.hs, Bug.o )\r\n\r\nBug.hs:7:23: error:\r\n • Expecting one more argument to ‘F’\r\n Expected a type, but ‘F’ has kind ‘* -> *’\r\n • In the type ‘F’\r\n In the type instance declaration for ‘T’\r\n |\r\n7 | type instance T Int = F\r\n | ^\r\n}}}\r\n\r\nIf GHC can point to the right place in the source code in this situation, then it ought to get the earlier situation right as well.","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/16394GHC internal error while typechecking of instance definition2019-07-07T18:00:15ZDay1721GHC internal error while typechecking of instance definitionHello. \\\\
This code won't typecheck because of GHC internal error.
```hs
{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}
class C a where
type T (n :: a)
-- v--DIFF--v
instance C a => C b => C (a, b) where
type T '(...Hello. \\\\
This code won't typecheck because of GHC internal error.
```hs
{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}
class C a where
type T (n :: a)
-- v--DIFF--v
instance C a => C b => C (a, b) where
type T '(n, m) = (T n, T m)
```
with error message:
```
Bug.hs:7:10: error:
• GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: [a1LS :-> Type variable ‘a’ = a :: *,
a1LT :-> Type variable ‘b’ = b :: *]
• In the type instance declaration for ‘T’
In the instance declaration for ‘C b => C (a, b)’
|
7 | type T (n, m) = (T n, T m)
| ^
Failed, no modules loaded.
```
but this works fine:
```hs
{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}
class C a where
type T (n :: a)
-- v--DIFF--v
instance (C a, C b) => C (a, b) where
type T '(n, m) = (T n, T m)
```
Not sure is a bug, but either way it would be better to make more understandable error message
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------------- |
| Version | 8.6.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | low |
| Resolution | Unresolved |
| Component | Compiler (Type checker) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GHC internal error while typechecking of instance definition","status":"New","operating_system":"","component":"Compiler (Type checker)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Hello. \\\\\r\nThis code won't typecheck because of GHC internal error.\r\n\r\n{{{#!hs\r\n{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n-- v--DIFF--v\r\ninstance C a => C b => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nwith error message: \r\n{{{\r\nBug.hs:7:10: error:\r\n • GHC internal error: ‘T’ is not in scope during type checking, but it passed the renamer\r\n tcl_env of environment: [a1LS :-> Type variable ‘a’ = a :: *,\r\n a1LT :-> Type variable ‘b’ = b :: *]\r\n • In the type instance declaration for ‘T’\r\n In the instance declaration for ‘C b => C (a, b)’\r\n |\r\n7 | type T (n, m) = (T n, T m)\r\n | ^\r\nFailed, no modules loaded.\r\n\r\n}}}\r\n\r\nbut this works fine:\r\n{{{#!hs\r\n{-# LANGUAGE PolyKinds, TypeFamilies, DataKinds #-}\r\n\r\nclass C a where\r\n type T (n :: a)\r\n\r\n-- v--DIFF--v\r\ninstance (C a, C b) => C (a, b) where\r\n type T '(n, m) = (T n, T m)\r\n}}}\r\n\r\nNot sure is a bug, but either way it would be better to make more understandable error message","type_of_failure":"OtherFailure","blocking":[]} -->8.8.1https://gitlab.haskell.org/ghc/ghc/-/issues/16551Spurious missing home modules warning in the present of hs-boot files2019-06-10T09:24:26ZMathieu BoespflugSpurious missing home modules warning in the present of hs-boot files# Summary
With `-Werror=missing-home-modules`, when `.hs-boot` files are involved, GHC fails the build even though all source files have been specified on the command-line.
# Steps to reproduce
Consider the following source files:
``...# Summary
With `-Werror=missing-home-modules`, when `.hs-boot` files are involved, GHC fails the build even though all source files have been specified on the command-line.
# Steps to reproduce
Consider the following source files:
```haskell
-- src/A.hs
module A where
import {-# SOURCE #-} B
-- src/B.hs
module B where
import A
-- src/B.hs-boot
module B where
```
The following command fails, while it is expected to succeed with no warning:
```
$ ghc -Werror=missing-home-modules src/A.hs src/B.hs
<no location info>: error: [-Wmissing-home-modules, -Werror=missing-home-modules]
Modules are not listed in command line but needed for compilation:
B
```
There is no way to satisfy GHC here, except to use `-isrc B` rather than `src/B.hs`. But that workaround doesn't help when only the filename is known, not the module name (in general the latter cannot be derived from the former).
# Environment
* GHC version used: 8.6.48.8.1