GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2023-09-12T09:36:00Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/22130`-fdefer-out-of-scope-variables` results in worse error messages for qualifie...2023-09-12T09:36:00ZZubin`-fdefer-out-of-scope-variables` results in worse error messages for qualified namesConsider the following files:
```haskell
module Data.List where
x :: Integer
x = 123
```
```haskell
module Bar where
import qualified Data.List as ThisList
wrong1 = ThisList.map
```
Compiling `Bar` with GHC 9.2 or 9.4, we get an accept...Consider the following files:
```haskell
module Data.List where
x :: Integer
x = 123
```
```haskell
module Bar where
import qualified Data.List as ThisList
wrong1 = ThisList.map
```
Compiling `Bar` with GHC 9.2 or 9.4, we get an acceptable error message:
```haskell
Main.hs:4:10: error:
Not in scope: ‘ThisList.map’
NB: the module ‘Data.List’ does not export ‘map’.
Suggested fix: Perhaps use ‘ThisList.x’ (imported from Data.List)
|
4 | wrong1 = ThisList.map
| ^^^^^^^^^^^^
```
However, with GHC 9.4, the error message changes (for the worse) with `-fdefer-out-of-scope-variables`:
```haskell
Main.hs:4:10: warning: [-Wdeferred-out-of-scope-variables]
Variable not in scope: map
Suggested fixes:
• Perhaps use one of these:
‘map’ (imported from Prelude), ‘max’ (imported from Prelude),
‘fmap’ (imported from Prelude)
• Perhaps you want to add ‘map’ to the import list in the import of
‘Prelude’ (Main.hs:2:8-10).
|
4 | wrong1 = ThisList.map
| ^^^^^^^^^^^^
```
This is a regression as the message doesn't change with `-fdefer-out-of-scope-variables` for GHC 9.2.9.4.4ZubinZubinhttps://gitlab.haskell.org/ghc/ghc/-/issues/23816Instances with Unsatisfiable context should use unsatisfiable for missing met...2023-08-22T18:17:56Zsheafsam.derbyshire@gmail.comInstances with Unsatisfiable context should use unsatisfiable for missing methods even when they have defaultsCurrently, we only generate method implementations for instances with an `Unsatisfiable` context when they have no default implementation. However, this can cause problems, e.g.
```haskell
{-# OPTIONS_GHC -fdefer-type-errors #-}
module...Currently, we only generate method implementations for instances with an `Unsatisfiable` context when they have no default implementation. However, this can cause problems, e.g.
```haskell
{-# OPTIONS_GHC -fdefer-type-errors #-}
module T23816 where
instance Unsatisfiable (Text "Msg") => Eq (a -> b)
bad = id == id
```
calling `bad` will result in a runtime loop due to `(==)` having a default definition in terms of `(/=)` and vice-versa, when we would rather it throws the unsatisfiable type error.
The fix is to change `GHC.Tc.TyCl.Instance.tc_default` to always create an `unsatisfiable` RHS even when there is a default method. I will execute.9.8.1sheafsam.derbyshire@gmail.comsheafsam.derbyshire@gmail.comhttps://gitlab.haskell.org/ghc/ghc/-/issues/16249no runtime error for -fdefer-type-errors with TypeError constraint2023-04-30T23:03:51ZGuillaume Bouchardno runtime error for -fdefer-type-errors with TypeError constraintPart of a testsuite, I'm using `-fdefer-type-errors` to check if haskell expression raises type error. However the haskell expression may be perfectly valid except for a `TypeError` constraint on a typeclass.
The following code:
```has...Part of a testsuite, I'm using `-fdefer-type-errors` to check if haskell expression raises type error. However the haskell expression may be perfectly valid except for a `TypeError` constraint on a typeclass.
The following code:
```haskell
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
import GHC.TypeLits
class Foo t where
foo :: t -> t
foo = id
instance Foo Int
instance (TypeError (Text "String does not work")) => Foo String
main :: IO ()
main = do
putStrLn (show (foo 10 :: Int))
putStrLn (foo "hello")
```
Correctly generates errors when compiled:
```
$ ghc ./DeferTypes.hs
[1 of 1] Compiling Main ( DeferTypes.hs, DeferTypes.o ) [flags changed]
DeferTypes.hs:17:13: error:
• String does not work
• In the first argument of ‘putStrLn’, namely ‘(foo "hello")’
In a stmt of a 'do' block: putStrLn (foo "hello")
In the expression:
do putStrLn (show (foo 10 :: Int))
putStrLn (foo "hello")
|
17 | putStrLn (foo "hello")
|
```
And also with `-fdefer-type-erros`, the error is transformed into a warning:
```
$ ghc -fdefer-type-errors ./DeferTypes.hs
[1 of 1] Compiling Main ( DeferTypes.hs, DeferTypes.o ) [flags changed]
DeferTypes.hs:17:13: warning: [-Wdeferred-type-errors]
• String does not work
• In the first argument of ‘putStrLn’, namely ‘(foo "hello")’
In a stmt of a 'do' block: putStrLn (foo "hello")
In the expression:
do putStrLn (show (foo 10 :: Int))
putStrLn (foo "hello")
|
17 | putStrLn (foo "hello")
| ^^^^^^^^^^^
Linking DeferTypes ...
```
However, executing the program gives no runtime error:
```
$ ./DeferTypes
10
hello
```
I was expecting something such as:
```
$ ./DeferTypes
10
[a defered type error exception]
```
With ghc 8.6.3 from nix.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.6.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":"no runtime error for -fdefer-type-errors with TypeError constraint","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Part of a testsuite, I'm using `-fdefer-type-errors` to check if haskell expression raises type error. However the haskell expression may be perfectly valid except for a `TypeError` constraint on a typeclass.\r\n\r\nThe following code:\r\n\r\n{{{#!haskell\r\n{-# LANGUAGE UndecidableInstances #-}\r\n{-# LANGUAGE FlexibleInstances #-}\r\n{-# LANGUAGE DataKinds #-}\r\n\r\nimport GHC.TypeLits\r\n\r\nclass Foo t where\r\n foo :: t -> t\r\n foo = id\r\n\r\ninstance Foo Int\r\ninstance (TypeError (Text \"String does not work\")) => Foo String\r\n\r\nmain :: IO ()\r\nmain = do\r\n putStrLn (show (foo 10 :: Int))\r\n putStrLn (foo \"hello\")\r\n}}}\r\n\r\nCorrectly generates errors when compiled:\r\n\r\n{{{\r\n$ ghc ./DeferTypes.hs\r\n[1 of 1] Compiling Main ( DeferTypes.hs, DeferTypes.o ) [flags changed]\r\n\r\nDeferTypes.hs:17:13: error:\r\n • String does not work\r\n • In the first argument of ‘putStrLn’, namely ‘(foo \"hello\")’\r\n In a stmt of a 'do' block: putStrLn (foo \"hello\")\r\n In the expression:\r\n do putStrLn (show (foo 10 :: Int))\r\n putStrLn (foo \"hello\")\r\n |\r\n17 | putStrLn (foo \"hello\")\r\n | \r\n}}}\r\n\r\nAnd also with `-fdefer-type-erros`, the error is transformed into a warning:\r\n\r\n{{{\r\n$ ghc -fdefer-type-errors ./DeferTypes.hs\r\n[1 of 1] Compiling Main ( DeferTypes.hs, DeferTypes.o ) [flags changed]\r\n\r\nDeferTypes.hs:17:13: warning: [-Wdeferred-type-errors]\r\n • String does not work\r\n • In the first argument of ‘putStrLn’, namely ‘(foo \"hello\")’\r\n In a stmt of a 'do' block: putStrLn (foo \"hello\")\r\n In the expression:\r\n do putStrLn (show (foo 10 :: Int))\r\n putStrLn (foo \"hello\")\r\n |\r\n17 | putStrLn (foo \"hello\")\r\n | ^^^^^^^^^^^\r\nLinking DeferTypes ...\r\n}}}\r\n\r\nHowever, executing the program gives no runtime error:\r\n{{{\r\n$ ./DeferTypes \r\n10\r\nhello\r\n}}}\r\n\r\nI was expecting something such as:\r\n\r\n{{{\r\n$ ./DeferTypes\r\n10\r\n[a defered type error exception]\r\n}}}\r\n\r\nWith ghc 8.6.3 from nix.\r\n","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/20472-fdefer-out-of-scope-variables should defer qualified names2023-01-06T19:32:54ZKrzysztof Gogolewski-fdefer-out-of-scope-variables should defer qualified namesThe following code fails to compile with `-fdefer-out-of-scope-variables`:
```
a = Prelude.nonexistent
b = Nonexistent.x
```
I think it should work, just like `a = nonexistent; b = nonexistent`.The following code fails to compile with `-fdefer-out-of-scope-variables`:
```
a = Prelude.nonexistent
b = Nonexistent.x
```
I think it should work, just like `a = nonexistent; b = nonexistent`.Matthew PickeringMatthew Pickeringhttps://gitlab.haskell.org/ghc/ghc/-/issues/22391`-fdefer-diagnostics` doesn't work in GHC 9.4.22022-12-13T09:30:59Zparsonsmatt`-fdefer-diagnostics` doesn't work in GHC 9.4.2## Summary
`-fdefer-diagnostics` no longer works in GHC 9.4.2
I created a reproduction repository here: https://github.com/parsonsmatt/defer-diagnostics-reproduction
## Steps to reproduce
```
git clone https://github.com/parsonsmatt/...## Summary
`-fdefer-diagnostics` no longer works in GHC 9.4.2
I created a reproduction repository here: https://github.com/parsonsmatt/defer-diagnostics-reproduction
## Steps to reproduce
```
git clone https://github.com/parsonsmatt/defer-diagnostics-reproduction
cd defer-diagnostics-reproduction
# set GHC 9.4.2
make warnings-deferred
# observe that warnings are interleaved in output
```
## Expected behavior
I would expect it to defer warnings and errors, like it does in GHC 9.2 and before
## Environment
* GHC version used: 9.4.2, 9.2.4
Optional:
* Operating System: Ubuntu
* System Architecture: x869.4.3https://gitlab.haskell.org/ghc/ghc/-/issues/21920TH and -fdefer-type-errors interaction2022-08-09T19:21:42ZKrzysztof GogolewskiTH and -fdefer-type-errors interactionThis code
```
p :: Bool
p = $$(const [|| True ||] ('a' + 'a'))
```
contains a type error in `'a' + 'a'` (no instance for `Num Char`). If `-fdefer-type-errors` is enabled, we can accept it.
Patch: !8711.This code
```
p :: Bool
p = $$(const [|| True ||] ('a' + 'a'))
```
contains a type error in `'a' + 'a'` (no instance for `Num Char`). If `-fdefer-type-errors` is enabled, we can accept it.
Patch: !8711.Matthew PickeringKrzysztof GogolewskiMatthew Pickeringhttps://gitlab.haskell.org/ghc/ghc/-/issues/18467Deferred type errors and the top level2022-06-03T18:56:17ZSimon Peyton JonesDeferred type errors and the top levelConsider
```
x = 3 -- Monomorphism restriction; we get x::alpha
f y = x::Float
g z = x::Int
```
Compiled with `-fdeferred-type-errors -dcore-lint` we get
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no lo...Consider
```
x = 3 -- Monomorphism restriction; we get x::alpha
f y = x::Float
g z = x::Int
```
Compiled with `-fdeferred-type-errors -dcore-lint` we get
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_a1ew :: Float ~# Int
*** Offending Program ***
Rec {
co_a1ew :: Float ~# Int
[LclId[CoVarId]]
co_a1ew
= typeError
@ ('TupleRep '[])
@ (Float ~# Int)
"Foo.hs:12:7: error:\n\
\ Couldn't match expected type 'Int' with actual type 'Float' \n\
\ In the expression: x :: Int\n\
\ In an equation for 'g': g z = x :: Int\n\
\(deferred type error)"#
```
The real error is that we make a top-level binding for a coercion, which is verboten.
Here's another way to trigger the same bug
```
f v = let x = \y -> (v, y : y) in True
```
We get
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_aZY :: Any ~# [Any]
*** Offending Program ***
Rec {
co_aZY :: Any ~# [Any]
[LclId[CoVarId]]
co_aZY
= typeError
@ ('TupleRep '[])
@ (Any ~# [Any])
"Foo.hs:14:29: error:\n\
\ Occurs check: cannot construct the infinite type: a0 ~ [a0]\n\
\ In the second argument of '(:)', namely 'y' \n\
\ In the expression: y : y\n\
\ In the expression: (v, y : y)\n\
\ Relevant bindings include\n\
\ y :: a0 (bound at Foo.hs:14:16)\n\
\ x :: a0 -> (a, [a0]) (bound at Foo.hs:14:11)\n\
\(deferred type error)"#
```
--------------------------
What is going on? It's simple: in `floatEqualities` we are, in both cases, floating a constraint `alpha ~ ty` to the top level.
Could we simply *not* float equalities to the top level? Alas that means that this program would fail to compile
```
x = 3
f y = x::Int
```
because we'd get an implication constraint `forall[1] b. alpha[0] ~# Int`, and we need to float that constraint to solve it with `alpha:=Int`.
-----------------
I'm a bit stumped about what to do here. It only matters for `-fdeferred-type-errors` because if we report the error and stop we'll never get to that Lint problem.https://gitlab.haskell.org/ghc/ghc/-/issues/20227Deferred type errors are too lazy, and can be dropped by Core optimisations2021-08-14T11:28:35Zsheafsam.derbyshire@gmail.comDeferred type errors are too lazy, and can be dropped by Core optimisationsThe mechanism for deferring type errors doesn't force the errors, meaning that programs that should fail with a deferred type error at runtime can be run without any errors. Consider the following example (from @rae):
```haskell
{-# LAN...The mechanism for deferring type errors doesn't force the errors, meaning that programs that should fail with a deferred type error at runtime can be run without any errors. Consider the following example (from @rae):
```haskell
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fdefer-type-errors #-}
module Main where
h :: Show (Int -> Int) => Int -> Int
h x = x
j :: Int
j = h 5
main :: IO ()
main = print j
```
```
./Main
5
```
This program runs without error, when one would have expected a type error about a missing `Show (Int -> Int)` instance. Richard points out that this can be a genuine security concern, for instance if constraints are used to ensure certain preconditions; a code-path that contains a type error can get run anyway!
The crux of the matter is that the evidence for `Show (Int -> Int)` is lifted:
```haskell
h :: Show (Int -> Int) => Int -> Int
h = \ ($dShow :: Show (Int -> Int)) (x :: Int) -> x
j :: Int
j = let {
$dShow :: Show (Int -> Int)
$dShow
= typeError @LiftedRep @(Show (Int -> Int))
"error:\n\
\ * No instance for (Show (Int -> Int)) arising from a use of `h'\n\
\ (maybe you haven't applied a function to enough arguments?)\n\
\ * In the expression: h 5\n\
\ In an equation for `j': j = h 5\n\
\(deferred type error)"# } in
h $dShow (I# 5#)
```
As `$dShow` is not forced in `j`, and is unused in `h`, Core optimisations drop the type error, resulting in
```haskell
j :: Int
j = I# 5#
```
Note that this problem doesn't arise for equality constraints, because their evidence is unlifted. For instance:
```haskell
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -fdefer-type-errors #-}
module Main where
h2 :: Int ~ Bool => Int -> Int
h2 x = x
j2 :: Int
j2 = h2 5
main :: IO ()
main = print j2
```
```
./Main
Main: Main.hs:11:6: error:
* Couldn't match type `Int' with `Bool' arising from a use of `h2'
* In the expression: h2 5
In an equation for `j2': j2 = h2 5
(deferred type error)
```
This is because `Int ~# Bool` is unlifted, meaning that we must `case` on it in Core:
```haskell
h2 :: (Int ~ Bool) => Int -> Int
h2 = \ ($d~:: Int ~ Bool) (x :: Int) -> x
j2 :: Int
j2
= case typeError @(TupleRep []) @(Int ~# Bool)
"error:\n\
\ * Couldn't match type `Int' with `Bool' arising from a use of `h2'\n\
\ * In the expression: h2 5\n\
\ In an equation for `j2': j2 = h2 5\n\
\(deferred type error)"#
of co
{ __DEFAULT ->
let {
$d~ :: Int ~ Bool
[LclId]
$d~
= Eq# @Type @Int @Bool @~(co :: Int ~# Bool) } in
h2 $d~ (I# 5#)
}
```
Notice the `case` statement on the `typeError`, instead of the `let` binding we saw in the previous example.
Richard suggested that we should make constraints unlifted (e.g. `Constraint ~ TYPE (BoxedRep Unlifted)` in Core), or, barring that, otherwise ensure that the evidence has been evaluated.
Note also that enabling `-fdicts-strict` does not make a difference to the issue reported here.
See also #11197 for the opposite issue (deferred type errors being evaluated too eagerly).https://gitlab.haskell.org/ghc/ghc/-/issues/19158ghci's :type still ignores ill-kinded type application with -fdefer-type-errors2021-08-02T17:29:55ZJakob Brünkerghci's :type still ignores ill-kinded type application with -fdefer-type-errors## Summary
#16376 was fixed in 8.10, but the same problem is still there if -fdefer-type-errors is enabled.
## Steps to reproduce
Write `:set -fdefer-type-errors` followed by `:t id @Maybe` in ghci. It produces no ouput, neither an er...## Summary
#16376 was fixed in 8.10, but the same problem is still there if -fdefer-type-errors is enabled.
## Steps to reproduce
Write `:set -fdefer-type-errors` followed by `:t id @Maybe` in ghci. It produces no ouput, neither an error nor anything else.
## Expected output
```
<interactive>:1:5: warning: [-Wdeferred-type-errors]:
• Expecting one more argument to ‘Maybe’
Expected a type, but ‘Maybe’ has kind ‘* -> *’
• In the type ‘Maybe’
In the expression: id @Maybe
id @Maybe :: t
```
## Environment
* GHC version used: 9.1.20201223
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_64https://gitlab.haskell.org/ghc/ghc/-/issues/19142panic lookup_final_id with -fdefer-type-errors and kind error in instance def...2021-01-22T21:09:33ZJakob Brünkerpanic lookup_final_id with -fdefer-type-errors and kind error in instance definition## Summary
This file
```haskell
{-# OPTIONS_GHC -fdefer-type-errors #-}
{-# LANGUAGE ExplicitForAll
, TypeApplications
, KindSignatures
, FlexibleInstances
#-}
foo :: forall (f :: * -> *) . String
foo ...## Summary
This file
```haskell
{-# OPTIONS_GHC -fdefer-type-errors #-}
{-# LANGUAGE ExplicitForAll
, TypeApplications
, KindSignatures
, FlexibleInstances
#-}
foo :: forall (f :: * -> *) . String
foo = ""
instance Show a where
show _ = foo @Int
```
produces the following error:
```
Bug.hs:12:17: warning: [-Wdeferred-type-errors]
• Expected kind ‘* -> *’, but ‘Int’ has kind ‘*’
• In the type ‘Int’
In the expression: foo @Int
In an equation for ‘show’: show _ = foo @Int
|
12 | show _ = foo @Int
| ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 9.0.0.20201227:
lookup_final_id
$fShowa
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Outputable.hs:1230:37 in ghc:GHC.Utils.Outputable
pprPanic, called at compiler/GHC/Iface/Tidy.hs:200:12 in ghc:GHC.Iface.Tidy
```
Without `-fdefer-type-errors`, only the kind error would be shown, not the panic.
## Expected behavior
GHC shouldn't panic
## Environment
* GHC version used: 9.0.0.20201227 as well as 8.10.2
Optional:
* Operating System: Ubuntu inside WSL2 inside Windows 10
* System Architecture: x86_64https://gitlab.haskell.org/ghc/ghc/-/issues/17812isUnliftedType panic with out of scope variable2020-12-29T15:36:39ZKrzysztof GogolewskiisUnliftedType panic with out of scope variableGiven
```haskell
{-# LANGUAGE RankNTypes, PolyKinds, KindSignatures #-}
module T where
import GHC.Types
bad :: forall (r :: RuntimeRep) a (b :: TYPE r). a -> b
bad x = outOfScope
```
attempting `ghc T.hs -fdefer-out-of-scope-variable...Given
```haskell
{-# LANGUAGE RankNTypes, PolyKinds, KindSignatures #-}
module T where
import GHC.Types
bad :: forall (r :: RuntimeRep) a (b :: TYPE r). a -> b
bad x = outOfScope
```
attempting `ghc T.hs -fdefer-out-of-scope-variables` shows:
```
T.hs:7:9: warning: [-Wdeferred-out-of-scope-variables]
Variable not in scope: outOfScope
|
7 | bad x = outOfScope
| ^^^^^^^^^^
ghc-stage2: panic! (the 'impossible' happened)
(GHC version 8.11.0.20200203:
isUnliftedType
b_au8 :: TYPE r_au6
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1187:37 in ghc:Outputable
pprPanic, called at compiler/types/Type.hs:1975:10 in ghc:Type
isUnliftedType, called at compiler/coreSyn/CoreUtils.hs:497:27 in ghc:CoreUtils
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
```
Tested on 8.6, 8.8 and HEAD.https://gitlab.haskell.org/ghc/ghc/-/issues/16877GHCi panics using -fdefer-type-errors when pattern matching on types with mul...2020-02-18T12:30:12ZBerengalGHCi panics using -fdefer-type-errors when pattern matching on types with multiple constructors using out-of-scope variables# Summary
With -fdefer-type-errors enabled GHCi will panic on certain errors involving pattern matching on types with multiple constructors. At least as far as I can tell.
# Steps to reproduce
The following is the smallest module I co...# Summary
With -fdefer-type-errors enabled GHCi will panic on certain errors involving pattern matching on types with multiple constructors. At least as far as I can tell.
# Steps to reproduce
The following is the smallest module I could find that causes the panic:
```
foo = x
where (x:xs) = bar
```
GHCi command and output:
```
▶ ghci -ignore-dot-ghci -fdefer-type-errors Foo.hs
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Foo.hs, interpreted )
Foo.hs:2:18: warning: [-Wdeferred-out-of-scope-variables]
Variable not in scope: bar :: [a1]
|
2 | where (x:xs) = bar
| ^^^
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64-unknown-linux):
getIdFromTrivialExpr
\ (@ a_a1x4) -> case ds_s1yU @ a_a1x4 of wild_Xb { }
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
pprPanic, called at compiler/coreSyn/CoreUtils.hs:977:18 in ghc:CoreUtils
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
>
```
The equivalent using `let` also panics. The pattern match in the where is neccessary, as is using a matched variable in the main expression (either one will do). Matching on a tuple does not cause a panic, nor does matching on `data Foo a = Foo a a`, but matching on `data Foo a = Foo a a | Bar a a` panics regardless of which constructor is chosen.
# Expected behavior
GHCi doesn't panic, but either loads the module correctly or explains why it can't do so.
# Environment
* GHC version used: 8.6.5
Optional:
* Operating System: Arch-linux
* System Architecture: x86_648.8.2https://gitlab.haskell.org/ghc/ghc/-/issues/14325Erroneous program emits no errors2019-07-07T18:17:28ZSimon Peyton JonesErroneous program emits no errorsConsider this (which arose in #14323):
```
class (a~b) => C a b
foo :: C a b => a -> b
foo x = x
hm3 :: C (f b) b => b -> f b
hm3 x = foo x
```
With GHC 8.2 it compiles without error, but it definitely has a type error; try `-ddump-s...Consider this (which arose in #14323):
```
class (a~b) => C a b
foo :: C a b => a -> b
foo x = x
hm3 :: C (f b) b => b -> f b
hm3 x = foo x
```
With GHC 8.2 it compiles without error, but it definitely has a type error; try `-ddump-simpl`:
```
hm3 :: forall (f :: * -> *) b. C (f b) b => b -> f b
[GblId, Arity=2, Str=<L,U><L,U>x]
hm3
= \ (@ (f_a126 :: * -> *))
(@ b_a127)
($dC_a129 :: C (f_a126 b_a127) b_a127)
_ [Occ=Dead] ->
case GHC.Types.HEq_sc
@ *
@ *
@ (f_a126 b_a127)
@ b_a127
($dC_a129
`cast` ((T14323.N:C[0] ; Data.Type.Equality.N:~[0]
<*>_N) <f_a126 b_a127>_N <b_a127>_N
:: (C (f_a126 b_a127) b_a127 :: Constraint)
~R# ((f_a126 b_a127 :: *) ~~ (b_a127 :: *) :: Constraint)))
of cobox_a12p
{ __DEFAULT ->
case Control.Exception.Base.typeError
@ 'GHC.Types.LiftedRep
@ (C b_a127 (f_a126 b_a127))
"T14323.hs:28:9: error:\n\
\ \\226\\128\\162 Could not deduce (C b (f b)) arising from a use of \\226\\128\\152foo\\226\\128\\153\n\
\ from the context: C (f b) b\n\
\ bound by the type signature for:\n\
\ hm3 :: forall (f :: * -> *) b. C (f b) b => b -> f b\n\
\ at T14323.hs:27:1-28\n\
\ \\226\\128\\162 In the expression: foo x\n\
\ In an equation for \\226\\128\\152hm3\\226\\128\\153: hm3 x = foo x\n\
\(deferred type error)"#
of wild_00 {
}
}
```
Reason: bug in the error suppression logic in `TcErrors`
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.2.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":"Erroneous program emits no errors","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Consider this (which arose in #14323):\r\n{{{\r\nclass (a~b) => C a b\r\n\r\nfoo :: C a b => a -> b\r\nfoo x = x\r\n\r\nhm3 :: C (f b) b => b -> f b\r\nhm3 x = foo x\r\n}}}\r\nWith GHC 8.2 it compiles without error, but it definitely has a type error; try `-ddump-simpl`:\r\n{{{\r\nhm3 :: forall (f :: * -> *) b. C (f b) b => b -> f b\r\n[GblId, Arity=2, Str=<L,U><L,U>x]\r\nhm3\r\n = \\ (@ (f_a126 :: * -> *))\r\n (@ b_a127)\r\n ($dC_a129 :: C (f_a126 b_a127) b_a127)\r\n _ [Occ=Dead] ->\r\n case GHC.Types.HEq_sc\r\n @ *\r\n @ *\r\n @ (f_a126 b_a127)\r\n @ b_a127\r\n ($dC_a129\r\n `cast` ((T14323.N:C[0] ; Data.Type.Equality.N:~[0]\r\n <*>_N) <f_a126 b_a127>_N <b_a127>_N\r\n :: (C (f_a126 b_a127) b_a127 :: Constraint)\r\n ~R# ((f_a126 b_a127 :: *) ~~ (b_a127 :: *) :: Constraint)))\r\n of cobox_a12p\r\n { __DEFAULT ->\r\n case Control.Exception.Base.typeError\r\n @ 'GHC.Types.LiftedRep\r\n @ (C b_a127 (f_a126 b_a127))\r\n \"T14323.hs:28:9: error:\\n\\\r\n \\ \\\\226\\\\128\\\\162 Could not deduce (C b (f b)) arising from a use of \\\\226\\\\128\\\\152foo\\\\226\\\\128\\\\153\\n\\\r\n \\ from the context: C (f b) b\\n\\\r\n \\ bound by the type signature for:\\n\\\r\n \\ hm3 :: forall (f :: * -> *) b. C (f b) b => b -> f b\\n\\\r\n \\ at T14323.hs:27:1-28\\n\\\r\n \\ \\\\226\\\\128\\\\162 In the expression: foo x\\n\\\r\n \\ In an equation for \\\\226\\\\128\\\\152hm3\\\\226\\\\128\\\\153: hm3 x = foo x\\n\\\r\n \\(deferred type error)\"#\r\n of wild_00 {\r\n }\r\n }\r\n}}}\r\nReason: bug in the error suppression logic in `TcErrors`","type_of_failure":"OtherFailure","blocking":[]} -->8.2.2https://gitlab.haskell.org/ghc/ghc/-/issues/14605Core Lint error2019-07-07T18:16:19ZIcelandjackCore Lint errorThis piece of code fails when run with `ghci -ignore-dot-ghci -fdefer-type-errors -dcore-lint bug.hs`, maybe same as my previous #14584.
```hs
{-# Language DerivingStrategies #-}
{-# Language GeneralizedNewtypeDeriving #-}
{-# Language ...This piece of code fails when run with `ghci -ignore-dot-ghci -fdefer-type-errors -dcore-lint bug.hs`, maybe same as my previous #14584.
```hs
{-# Language DerivingStrategies #-}
{-# Language GeneralizedNewtypeDeriving #-}
{-# Language InstanceSigs #-}
{-# Language KindSignatures #-}
{-# Language PolyKinds #-}
{-# Language ScopedTypeVariables #-}
{-# Language TypeApplications #-}
{-# Language TypeFamilies #-}
{-# Language TypeInType #-}
{-# Language TypeOperators #-}
{-# Language UndecidableInstances #-}
import Data.Kind
import Data.Functor.Identity
import Data.Functor.Product
type a <-> b = a -> b -> Type
class Iso (iso :: a <-> b) where
iso :: a -> b
osi :: b -> a
data Iso_Bool :: Either () () <-> Bool
instance Iso Iso_Bool where
class Representable f where
type Rep f :: Type
index :: f a -> (Rep f -> a)
tabulate :: (Rep f -> a) -> f a
class Comonad w where
extract :: w a -> a
duplicate :: w a -> w (w a)
newtype Co f a = Co (f a) deriving newtype (Functor, Representable)
instance (Representable f, Monoid (Rep f)) => Comonad (Co f) where
extract = (`index` mempty)
newtype WRAP (iso::old <-> new) f a = WRAP (f a)
instance (Representable f, Rep f ~ old, Iso iso) => Representable (WRAP (iso :: old <-> new) f) where
type Rep (WRAP (iso :: old <-> new) f) = new
index :: WRAP iso f a -> (new -> a)
index (WRAP fa) = index fa . osi @old @new @iso
tabulate :: (new -> a) -> WRAP iso f a
tabulate gen = WRAP $
tabulate (gen . iso @old @new @iso)
newtype PAIR a = PAIR (Co (WRAP Iso_Bool (Product Identity Identity)) a)
deriving newtype
Comonad
```
I unfortunately don't have time to find a more minimal example. Core linter vomits a lot of errors on 8.2.1 & 8.3.20171208.
<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":"Core Lint error","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.2.2","keywords":["DeferredTypeErrors","TypeInType,"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"This piece of code fails when run with `ghci -ignore-dot-ghci -fdefer-type-errors -dcore-lint bug.hs`, maybe same as my previous #14584.\r\n\r\n{{{#!hs\r\n{-# Language DerivingStrategies #-}\r\n{-# Language GeneralizedNewtypeDeriving #-}\r\n{-# Language InstanceSigs #-}\r\n{-# Language KindSignatures #-}\r\n{-# Language PolyKinds #-}\r\n{-# Language ScopedTypeVariables #-}\r\n{-# Language TypeApplications #-}\r\n{-# Language TypeFamilies #-}\r\n{-# Language TypeInType #-}\r\n{-# Language TypeOperators #-}\r\n{-# Language UndecidableInstances #-}\r\n\r\nimport Data.Kind\r\nimport Data.Functor.Identity\r\nimport Data.Functor.Product\r\n\r\ntype a <-> b = a -> b -> Type\r\n\r\nclass Iso (iso :: a <-> b) where\r\n iso :: a -> b\r\n osi :: b -> a\r\n\r\ndata Iso_Bool :: Either () () <-> Bool\r\n\r\ninstance Iso Iso_Bool where\r\n\r\nclass Representable f where\r\n type Rep f :: Type\r\n\r\n index :: f a -> (Rep f -> a)\r\n tabulate :: (Rep f -> a) -> f a\r\n\r\nclass Comonad w where\r\n extract :: w a -> a\r\n duplicate :: w a -> w (w a)\r\n\r\nnewtype Co f a = Co (f a) deriving newtype (Functor, Representable)\r\n\r\ninstance (Representable f, Monoid (Rep f)) => Comonad (Co f) where\r\n extract = (`index` mempty)\r\n\r\nnewtype WRAP (iso::old <-> new) f a = WRAP (f a)\r\n\r\ninstance (Representable f, Rep f ~ old, Iso iso) => Representable (WRAP (iso :: old <-> new) f) where\r\n type Rep (WRAP (iso :: old <-> new) f) = new\r\n\r\n index :: WRAP iso f a -> (new -> a)\r\n index (WRAP fa) = index fa . osi @old @new @iso\r\n\r\n tabulate :: (new -> a) -> WRAP iso f a\r\n tabulate gen = WRAP $ \r\n tabulate (gen . iso @old @new @iso)\r\n\r\nnewtype PAIR a = PAIR (Co (WRAP Iso_Bool (Product Identity Identity)) a)\r\n deriving newtype\r\n Comonad \r\n}}}\r\n\r\nI unfortunately don't have time to find a more minimal example. Core linter vomits a lot of errors on 8.2.1 & 8.3.20171208. ","type_of_failure":"OtherFailure","blocking":[]} -->https://gitlab.haskell.org/ghc/ghc/-/issues/14607Core Lint error2019-07-07T18:16:18ZIcelandjackCore Lint errorThis produces a long Core lint error:
```hs
{-# Language DerivingStrategies #-}
{-# Language GADTs #-}
{-# Language GeneralizedNewtypeDeriving #-}
{-# Language InstanceSigs #-}
{-# Language KindSignatures #-}
{-# Language TypeFamilies #...This produces a long Core lint error:
```hs
{-# Language DerivingStrategies #-}
{-# Language GADTs #-}
{-# Language GeneralizedNewtypeDeriving #-}
{-# Language InstanceSigs #-}
{-# Language KindSignatures #-}
{-# Language TypeFamilies #-}
{-# Language TypeInType #-}
{-# Language TypeOperators #-}
import Data.Kind
data DEFUNC :: Type -> Type -> Type where
(:~>) :: a -> b -> DEFUNC a b
type a ~> b = DEFUNC a b -> Type
data LamCons a :: Type ~> Type where
LamCons :: a -> LamCons a ([a] :~> [a])
class Mk (app :: Type ~> Type) where
type Arg app :: Type
mk :: Arg app -> app (a :~> b)
instance Mk (LamCons a :: Type ~> Type) where
type Arg (LamCons a) = a
mk :: a -> LamCons (a :~> b)
mk = LamCons
```
with `ghci -ignore-dot-ghci -fdefer-type-errors -dcore-lint bug.hs` on GHC 8.2.1 and 8.3.20171208.