GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2024-02-15T15:43:46Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/24413Re-Enable `-fdefer-type-errors` and `-fdefer-out-of-scope-variables` in GHCi2024-02-15T15:43:46ZApoorv IngleRe-Enable `-fdefer-type-errors` and `-fdefer-out-of-scope-variables` in GHCi## Summary
GHCi has `-fdefer-type-errors` and `-fdefer-out-of-scope-variables` was disabled as an adhoc fix to avoid some serious issue #14963.
Now that the real issue is fixed by we should re-enable `-fdefer-type-errors` and `-fdefer-...## Summary
GHCi has `-fdefer-type-errors` and `-fdefer-out-of-scope-variables` was disabled as an adhoc fix to avoid some serious issue #14963.
Now that the real issue is fixed by we should re-enable `-fdefer-type-errors` and `-fdefer-out-of-scope-variables` in GHCi.
More info: https://gitlab.haskell.org/ghc/ghc/-/issues/14963#note_546391
## Steps to reproduce
Check #14963
## Expected behavior
Code snippet in #14963 shouldn't crash
## Environment
* GHC version used: HEADApoorv IngleApoorv Inglehttps://gitlab.haskell.org/ghc/ghc/-/issues/24026Core Lint error with -fdefer-type-errors and bad RULE2023-10-03T14:12:23ZKrzysztof GogolewskiCore Lint error with -fdefer-type-errors and bad RULETo reproduce:
```hs
module T24026 where
{-# RULES "f" forall (x :: Bool). f x = 0 #-}
f :: Int -> Int
f x = 0
```
```
$ ghc -dlint -fdefer-type-errors T24026
[1 of 1] Compiling T24026 ( T24026.hs, T24026.o )
*** Core Lint e...To reproduce:
```hs
module T24026 where
{-# RULES "f" forall (x :: Bool). f x = 0 #-}
f :: Int -> Int
f x = 0
```
```
$ ghc -dlint -fdefer-type-errors T24026
[1 of 1] Compiling T24026 ( T24026.hs, T24026.o )
*** Core Lint errors : in result of Desugar (before optimization) ***
T24026.hs:6:1: warning:
The coercion variable co_awP :: Bool ~# Int
[LclId[CoVarId]]
is out of scope
In the RHS of f :: Int -> Int
In a rule attached to f :: Int -> Int
Substitution: <InScope = {}
IdSubst = []
TvSubst = []
CvSubst = []>
*** Offending Program ***
Rec {
$trModule :: Module
[LclIdX]
$trModule = Module (TrNameS "main"#) (TrNameS "T24026"#)
f :: Int -> Int
[LclIdX,
RULES: "f" forall (x_awv :: Bool).
f (x_awv `cast` (Sub co_awP :: Bool ~R# Int))
= I# 0#]
f = \ (x_awu :: Int) -> I# 0#
end Rec }
````
The RULE has a type error, the coercion `Int ~ Bool` from `-fdefer-type-errors` is not bound.9.10.1https://gitlab.haskell.org/ghc/ghc/-/issues/24024Assertion failure with ghci -fdefer-type-errors2023-11-01T14:47:25ZKrzysztof GogolewskiAssertion failure with ghci -fdefer-type-errorsTo reproduce:
```
$ ./stage1/bin/ghc --interactive
GHCi, version 9.9.20230927: https://www.haskell.org/ghc/ :? for help
ghci> :set -fdefer-type-errors
ghci> :kind Int Int
panic! (the 'impossible' happened)
GHC version 9.9.20230927:
...To reproduce:
```
$ ./stage1/bin/ghc --interactive
GHCi, version 9.9.20230927: https://www.haskell.org/ghc/ :? for help
ghci> :set -fdefer-type-errors
ghci> :kind Int Int
panic! (the 'impossible' happened)
GHC version 9.9.20230927:
ASSERT failed!
{[W] co_aBU
= case typeError
@LiftedRep
@()
"<interactive>:1:1: error: [\ESC]8;;https://errors.haskell.org/messages/GHC-83865\ESC\\GHC-83865\ESC]8;;\ESC\\]\n\
\ \\226\\128\\162 Expected kind \\226\\128\\152* -> k0\\226\\128\\153, but \\226\\128\\152Int\\226\\128\\153 has kind \\226\\128\\152*\\226\\128\\153\n\
\ \\226\\128\\162 In the type \\226\\128\\152Int Int\\226\\128\\153\n\
\(deferred type error)"#
of {}}
Call stack:
CallStack (from HasCallStack):
massertPpr, called at compiler/GHC/Tc/Module.hs:2626:10 in ghc-9.9-inplace:GHC.Tc.Module
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:511:29 in ghc-9.9-inplace:GHC.Utils.Error
```
Even with assertions off we get a rather silly output
```
:set -fdefer-type-errors
ghci> :k Int Int
<interactive>:1:1: warning: [GHC-83865] [-Wdeferred-type-errors]
• Expected kind ‘* -> k0’, but ‘Int’ has kind ‘*’
• In the type ‘Int Int’
Int Int :: k
```9.8.2Krzysztof GogolewskiKrzysztof Gogolewskihttps://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/23258-fdefer-typed-holes will raise "(deferred type error)" exception, and that na...2023-06-10T12:20:55Zjwaldmann-fdefer-typed-holes will raise "(deferred type error)" exception, and that name looks wrongwith ghc-9.6.1,
```
:set -fdefer-typed-holes
ghci> x = [True,_] -- gives warning, as expected
ghci> print x
[True,*** Exception: <interactive>:11:11: error: [GHC-88464]
...
(deferred type error)
```
that last line looks wrong to me, s...with ghc-9.6.1,
```
:set -fdefer-typed-holes
ghci> x = [True,_] -- gives warning, as expected
ghci> print x
[True,*** Exception: <interactive>:11:11: error: [GHC-88464]
...
(deferred type error)
```
that last line looks wrong to me, since there is no type error. Documentation says "a hole ... will behave like undefined", and for that I would get no type error.https://gitlab.haskell.org/ghc/ghc/-/issues/23111Core Lint error with -fdefer-type-errors and kind error2023-03-14T15:16:29ZKrzysztof GogolewskiCore Lint error with -fdefer-type-errors and kind errorThe following program fails `ghc -dcore-lint -fdefer-type-errors`
```haskell
{-# LANGUAGE TypeFamilies #-}
module M where
import Data.Kind
type F :: Type
type family F
type G :: F
type family G
x :: G
x = ()
```
<details>
```haske...The following program fails `ghc -dcore-lint -fdefer-type-errors`
```haskell
{-# LANGUAGE TypeFamilies #-}
module M where
import Data.Kind
type F :: Type
type family F
type G :: F
type family G
x :: G
x = ()
```
<details>
```haskell
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_awK :: F ~# *
Substitution: <InScope = {}
IdSubst = []
TvSubst = []
CvSubst = []>
*** Offending Program ***
Rec {
co_awK :: F ~# *
[LclId[CoVarId]]
co_awK
= case typeError
@LiftedRep
@()
"M.hs:12:6: error: [GHC-83865]\n\
\ \\226\\128\\162 Expected a type, but \\226\\128\\152G\\226\\128\\153 has kind \\226\\128\\152F\\226\\128\\153\n\
\ \\226\\128\\162 In the type signature: x :: G\n\
\(deferred type error)"#
of wild_00 {
}
$trModule :: Module
[LclIdX]
$trModule = Module (TrNameS "main"#) (TrNameS "M"#)
x :: (G |> co_awK)
[LclIdX]
x = case case typeError
@LiftedRep
@()
"M.hs:13:5: error: [GHC-18872]\n\
\ \\226\\128\\162 Couldn't match kind \\226\\128\\152F\\226\\128\\153 with \\226\\128\\152*\\226\\128\\153\n\
\ When matching types\n\
\ G :: F\n\
\ () :: *\n\
\ \\226\\128\\162 In the expression: ()\n\
\ In an equation for \\226\\128\\152x\\226\\128\\153: x = ()\n\
\(deferred type error)"#
of wild_00 {
}
of co_ayG
{ __DEFAULT ->
case case typeError
@LiftedRep
@()
"M.hs:13:5: error: [GHC-18872]\n\
\ \\226\\128\\162 Couldn't match kind \\226\\128\\152F\\226\\128\\153 with \\226\\128\\152*\\226\\128\\153\n\
\ When matching types\n\
\ G :: F\n\
\ () :: *\n\
\ \\226\\128\\162 In the expression: ()\n\
\ In an equation for \\226\\128\\152x\\226\\128\\153: x = ()\n\
\(deferred type error)"#
of wild_00 {
}
of co_ayH
{ __DEFAULT ->
()
`cast` (Sub (Sym (co_ayH
; Sym (GRefl nominal () (Sym co_ayG)))
; GRefl nominal G co_awK)
:: () ~R# (G |> co_awK))
}
}
end Rec }
```
</details>https://gitlab.haskell.org/ghc/ghc/-/issues/22642Allow signatures without a binding2023-07-20T16:15:02ZOleg GrenrusAllow signatures without a bindingIn other words so I can write
```haskell
someFancyFunction :: a -> (forall b. b -> c) -> (a -> b) -> c
```
currently GHC errors
```
Top.hs:3:1: error:
The type signature for ‘someFancyFunction’
lacks an accompanying binding
...In other words so I can write
```haskell
someFancyFunction :: a -> (forall b. b -> c) -> (a -> b) -> c
```
currently GHC errors
```
Top.hs:3:1: error:
The type signature for ‘someFancyFunction’
lacks an accompanying binding
|
3 | someFancyFunction :: a -> (forall b. b -> c) -> (a -> b) -> c
| ^^
```
Though one can simulate the behavior by compiling with `-fdefer-type-errors` and supplying some non-sense implementation:
```haskell
someFancyFunction :: a -> (forall b. b -> c) -> (a -> b) -> c
someFancyFunction = ()
```
An alternative is to write
```haskell
someFancyFunction :: a -> (forall b. b -> c) -> (a -> b) -> c
someFancyFunction x y z = someFancyFunction x y z
```
or
```haskell
someFancyFunction _x _y _z = undefined -- need to eta-expand because of rankN argument
```
But both of these are not great option: it's very easy to leave the "temporary" placeholders into the code base. GHC cannot help to find them. (it can with `-fdefer-type-errors` trick, but that feels roundabout - and does "too much" on the side).
I argue that very similar functionality already exists in GHC: missing type class members and missing record fields are filled by GHC. These issue warnings which can be turned into errors. Missing binding for a signature could also be a warning, which is an error by default. Or it could be a `-f..` flag.
I think it will be very useful for interactive development, so GHC don't error too early.9.10.1https://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/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/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/21692Static pointers + defer-type-errors Lint error2022-09-01T15:55:11ZKrzysztof GogolewskiStatic pointers + defer-type-errors Lint errorThis program fails Lint with `-fdefer-type-errors`:
```haskell
{-# LANGUAGE StaticPointers #-}
module T where
import GHC.StaticPtr
p :: StaticPtr Bool
p = static 'a'
```
```
*** Core Lint errors : in result of Desugar (before optimiz...This program fails Lint with `-fdefer-type-errors`:
```haskell
{-# LANGUAGE StaticPointers #-}
module T where
import GHC.StaticPtr
p :: StaticPtr Bool
p = static 'a'
```
```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_avC :: Char ~# Bool
Substitution: [TCvSubst
In scope: InScope {}
Type env: []
Co env: []]
*** Offending Program ***
Rec {
co_avC :: Char ~# Bool
[LclId[CoVarId]]
co_avC
= case typeError ...
```
If Lint is disabled, it fails with an assertion failure or a panic.
Related: #18467https://gitlab.haskell.org/ghc/ghc/-/issues/21024A deferred type error inferferes with the monomorphism restriction2022-06-09T14:31:57ZRichard Eisenbergrae@richarde.devA deferred type error inferferes with the monomorphism restrictionHere is a fairly simple program:
```
{-# OPTIONS_GHC -fdefer-type-errors #-}
module Bug where
other = ['a', True]
x = 5
```
The monomorphism restriction is in effect, and note that the two definitions do not refer to each other.
GH...Here is a fairly simple program:
```
{-# OPTIONS_GHC -fdefer-type-errors #-}
module Bug where
other = ['a', True]
x = 5
```
The monomorphism restriction is in effect, and note that the two definitions do not refer to each other.
GHC embarrassingly infers the type `Any` for `x`, affected by the presence of the ill-typed `other`.https://gitlab.haskell.org/ghc/ghc/-/issues/20511Missing module imports could be defered with -fdefer-out-scope-variables?2021-10-19T15:06:03ZMatthew PickeringMissing module imports could be defered with -fdefer-out-scope-variables?If I write a module with a non-existent then you get an error such as:
```
A.hs:3:1: error:
Could not find module ‘FooBaz’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import FooBaz
| ^^^^^^^^...If I write a module with a non-existent then you get an error such as:
```
A.hs:3:1: error:
Could not find module ‘FooBaz’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import FooBaz
| ^^^^^^^^^^^^^
```
but if we turn on `-fdefer-out-of-scope-variables` then we might expect that we could continue and get more interesting diagnostics for the rest of the module. A missing module could be thought of as an out-of-scope variable.
One issue with this scheme is that identifiers which would come from this module would then be reported as out-of-scope which could cause additional confusion due to the cascading nature of deferred errors.
What do you think @wz1000 @monoidal ?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/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/20083Linear types and -fdefer-type-errors2024-02-09T00:47:35ZKrzysztof GogolewskiLinear types and -fdefer-type-errorsLinear types combined with `-fdefer-type-errors` show a poor error message.
```
ghci> :set -XLinearTypes
ghci> ap :: (a -> b) -> a %m -> b; ap f x = f x
<interactive>:2:35: error:
• Couldn't match type ‘m’ with ‘'Many’
aris...Linear types combined with `-fdefer-type-errors` show a poor error message.
```
ghci> :set -XLinearTypes
ghci> ap :: (a -> b) -> a %m -> b; ap f x = f x
<interactive>:2:35: error:
• Couldn't match type ‘m’ with ‘'Many’
arising from multiplicity of ‘x’
‘m’ is a rigid type variable bound by
the type signature for:
ap :: forall a b (m :: GHC.Types.Multiplicity).
(a -> b) -> a %m -> b
at <interactive>:2:1-27
• In an equation for ‘ap’: ap f x = f x
• Relevant bindings include
ap :: (a -> b) -> a %m -> b (bound at <interactive>:2:30)
ghci> :set -fdefer-type-errors
ghci> ap :: (a -> b) -> a %m -> b; ap f x = f x
<interactive>:4:30: error:
Multiplicity coercions are currently not supported (see GHC #19517)
<interactive>:4:30: error:
Multiplicity coercions are currently not supported (see GHC #19517)
```
The error message is technically correct, but `-fdefer-type-errors` downgrades the type mismatch to a warning. The warning is not shown, while it contains important information.
Until #19517 is done, when `-fdefer-type-errors` is on, we should compile multiplicity coercions to runtime errors and convert the error to a warning.
Also make the message more user-friendly.https://gitlab.haskell.org/ghc/ghc/-/issues/19966Out-of-scope variables not deferred with type constructors2021-06-11T21:00:38ZKrzysztof GogolewskiOut-of-scope variables not deferred with type constructorsIn HEAD, `-fdefer-out-of-scope-variables` can no longer defer an out-of-scope identifier if it exists on the type level.
```
ghci> :set -fdefer-out-of-scope-variables
ghci> x = I
<interactive>:2:5: warning: [-Wdeferred-out-of-scope-va...In HEAD, `-fdefer-out-of-scope-variables` can no longer defer an out-of-scope identifier if it exists on the type level.
```
ghci> :set -fdefer-out-of-scope-variables
ghci> x = I
<interactive>:2:5: warning: [-Wdeferred-out-of-scope-variables]
Data constructor not in scope: I
ghci> x = IO
<interactive>:3:5: error:
• Illegal term-level use of the type constructor ‘IO’
imported from ‘Prelude’ (and originally defined in ‘GHC.Types’)
• In the expression: IO
In an equation for ‘x’: x = IO
```
In 9.0, `x = IO` behaves the same as `x = I`.
With Dependent Haskell we might ultimately allow `x = IO` to mean the type constructor, but the current situation is a bit inconsistent.
Low priority. Related: #17102.Vladislav ZavialovVladislav Zavialovhttps://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/18636RebindableSyntax cannot defer-out-of-scope-variables2021-02-16T21:02:59ZRichard Eisenbergrae@richarde.devRebindableSyntax cannot defer-out-of-scope-variablesWhen I say
```hs
{-# LANGUAGE RebindableSyntax #-}
{-# OPTIONS_GHC -fdefer-out-of-scope-variables #-}
module Bug where
foo = 5
```
I get
```
Bug.hs:6:7: error: Not in scope: ‘fromInteger’
```
But I told GHC to defer such errors!
N...When I say
```hs
{-# LANGUAGE RebindableSyntax #-}
{-# OPTIONS_GHC -fdefer-out-of-scope-variables #-}
module Bug where
foo = 5
```
I get
```
Bug.hs:6:7: error: Not in scope: ‘fromInteger’
```
But I told GHC to defer such errors!
Nobody is really asking for this (I was just trying to abuse GHC for fun), but I think it should be very very easy to implement.