Commit 350e2b78 authored by Richard Eisenberg's avatar Richard Eisenberg Committed by Marge Bot

Don't zap to Any; error instead

This changes GHC's treatment of so-called Naughty Quantification
Candidates to issue errors, instead of zapping to Any.

Close #16775.

No new test cases, because existing ones cover this well.
parent 9129210f
Pipeline #14484 failed with stages
in 382 minutes and 6 seconds
......@@ -94,7 +94,7 @@ module OccName (
-- * Tidying up
TidyOccEnv, emptyTidyOccEnv, initTidyOccEnv,
tidyOccName, avoidClashesOccEnv,
tidyOccName, avoidClashesOccEnv, delTidyOccEnvList,
-- FsEnv
FastStringEnv, emptyFsEnv, lookupFsEnv, extendFsEnv, mkFsEnv
......@@ -818,7 +818,7 @@ Every id contributes a type variable to the type signature, and all of them are
(id,id,id) :: (a2 -> a2, a1 -> a1, a -> a)
which is a bit unfortunate, as it unfairly renames only one of them. What we
which is a bit unfortunate, as it unfairly renames only two of them. What we
would like to see is
(id,id,id) :: (a3 -> a3, a2 -> a2, a1 -> a1)
......@@ -846,6 +846,9 @@ initTidyOccEnv = foldl' add emptyUFM
where
add env (OccName _ fs) = addToUFM env fs 1
delTidyOccEnvList :: TidyOccEnv -> [FastString] -> TidyOccEnv
delTidyOccEnvList = delListFromUFM
-- see Note [Tidying multiple names at once]
avoidClashesOccEnv :: TidyOccEnv -> [OccName] -> TidyOccEnv
avoidClashesOccEnv env occs = go env emptyUFM occs
......
......@@ -71,13 +71,14 @@ module VarEnv (
-- * TidyEnv and its operation
TidyEnv,
emptyTidyEnv, mkEmptyTidyEnv
emptyTidyEnv, mkEmptyTidyEnv, delTidyEnvList
) where
import GhcPrelude
import qualified Data.IntMap.Strict as IntMap -- TODO: Move this to UniqFM
import OccName
import Name
import Var
import VarSet
import UniqSet
......@@ -424,6 +425,12 @@ emptyTidyEnv = (emptyTidyOccEnv, emptyVarEnv)
mkEmptyTidyEnv :: TidyOccEnv -> TidyEnv
mkEmptyTidyEnv occ_env = (occ_env, emptyVarEnv)
delTidyEnvList :: TidyEnv -> [Var] -> TidyEnv
delTidyEnvList (occ_env, var_env) vs = (occ_env', var_env')
where
occ_env' = occ_env `delTidyOccEnvList` map (occNameFS . getOccName) vs
var_env' = var_env `delVarEnvList` vs
{-
************************************************************************
* *
......
......@@ -1770,7 +1770,7 @@ the surrounding context, we must obey the following dictum:
Every metavariable in a type must either be
(A) generalized, or
(B) promoted, or See Note [Promotion in signatures]
(C) zapped to Any See Note [Naughty quantification candidates] in TcMType
(C) a cause to error See Note [Naughty quantification candidates] in TcMType
The kindGeneralize functions do not require pre-zonking; they zonk as they
go.
......
This diff is collapsed.
......@@ -237,7 +237,7 @@ dependentArgErr (arg, bad_cos)
~~-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
data AST a = Sym [a]
class Prj s where { prj :: [a] -> Maybe (s a)
class Prj s where { prj :: [a] -> Maybe (s a) }
pattern P x <= Sym (prj -> Just x)
Here we get a matcher with this type
......@@ -261,7 +261,7 @@ mentions the existentials. We can conveniently do that by making the
forall ex_tvs. arg_ty
After that, Note [Naughty quantification candidates] in TcMType takes
over, and zonks any such naughty variables to Any.
over and errors.
Note [Remove redundant provided dicts]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -5,7 +5,7 @@ module TyCoPpr
PprPrec(..), topPrec, sigPrec, opPrec, funPrec, appPrec, maybeParen,
-- * Pretty-printing types
pprType, pprParendType, pprPrecType, pprPrecTypeX,
pprType, pprParendType, pprTidiedType, pprPrecType, pprPrecTypeX,
pprTypeApp, pprTCvBndr, pprTCvBndrs,
pprSigmaType,
pprTheta, pprParendTheta, pprForAll, pprUserForAll,
......@@ -81,10 +81,13 @@ See Note [Precedence in types] in BasicTypes.
-- See Note [Pretty printing via Iface syntax] in PprTyThing
--------------------------------------------------------
pprType, pprParendType :: Type -> SDoc
pprType, pprParendType, pprTidiedType :: Type -> SDoc
pprType = pprPrecType topPrec
pprParendType = pprPrecType appPrec
-- already pre-tidied
pprTidiedType = pprIfaceType . toIfaceTypeX emptyVarSet
pprPrecType :: PprPrec -> Type -> SDoc
pprPrecType = pprPrecTypeX emptyTidyEnv
......
......@@ -95,8 +95,8 @@ tidyTyCoVarBinders tidy_env tvbs
tidyFreeTyCoVars :: TidyEnv -> [TyCoVar] -> TidyEnv
-- ^ Add the free 'TyVar's to the env in tidy form,
-- so that we can tidy the type they are free in
tidyFreeTyCoVars (full_occ_env, var_env) tyvars
= fst (tidyOpenTyCoVars (full_occ_env, var_env) tyvars)
tidyFreeTyCoVars tidy_env tyvars
= fst (tidyOpenTyCoVars tidy_env tyvars)
---------------
tidyOpenTyCoVars :: TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
......@@ -232,5 +232,3 @@ tidyCo env@(_, subst) co
tidyCos :: TidyEnv -> [Coercion] -> [Coercion]
tidyCos env = map (tidyCo env)
......@@ -34,7 +34,7 @@ module Outputable (
sep, cat,
fsep, fcat,
hang, hangNotEmpty, punctuate, ppWhen, ppUnless,
speakNth, speakN, speakNOf, plural, isOrAre, doOrDoes,
speakNth, speakN, speakNOf, plural, isOrAre, doOrDoes, itsOrTheir,
unicodeSyntax,
coloured, keyword,
......@@ -1160,6 +1160,15 @@ doOrDoes :: [a] -> SDoc
doOrDoes [_] = text "does"
doOrDoes _ = text "do"
-- | Determines the form of possessive appropriate for the length of a list:
--
-- > itsOrTheir [x] = text "its"
-- > itsOrTheir [x,y] = text "their"
-- > itsOrTheir [] = text "their" -- probably avoid this
itsOrTheir :: [a] -> SDoc
itsOrTheir [_] = text "its"
itsOrTheir _ = text "their"
{-
************************************************************************
* *
......
......@@ -18,6 +18,12 @@ Full details
Language
~~~~~~~~
* In obscure scenarios, GHC now rejects programs it previously accepted, but
with unhelpful types. For example, if (with ``-XPartialTypeSignatures``) you
were to write ``x :: forall (f :: forall a (b :: a -> Type). b _). f _``, GHC previously
would have accepted ``x``, but its type would have involved the mysterious ``Any``
internal type family. Now, GHC rejects, explaining the situation.
Compiler
~~~~~~~~
......
......@@ -54,13 +54,9 @@ test('T15419', normal, compile, [''])
test('T14066h', normal, compile, [''])
test('T15666', normal, compile, [''])
test('T15725', normal, compile, [''])
test('T14880', normal, compile, [''])
test('T14880-2', normal, compile, [''])
test('T15743', normal, compile, ['-ddump-types -fprint-explicit-foralls'])
test('InferDependency', normal, compile, [''])
test('T15743e', normal, compile, ['-ddump-types -fprint-explicit-foralls'])
test('T15076', normal, compile, [''])
test('T15076b', normal, compile, [''])
test('T15076c', normal, compile, [''])
test('T15829', normal, compile, [''])
test('T14729', normal, compile, ['-ddump-types -fprint-typechecker-elaboration -fprint-explicit-coercions'])
......
T14880-2.hs:12:9: error:
• Cannot generalise type; skolem ‘arg’ would escape its scope
if I tried to quantify (a0 :: arg) in this type:
forall arg. Proxy @{Proxy @{arg} a0 -> *} (Foo arg @a0) -> ()
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature: quux :: forall arg. Proxy (Foo arg) -> ()
T14880.hs:12:5: error:
• Cannot generalise type; skolem ‘arg’ would escape its scope
if I tried to quantify (a0 :: arg) in this type:
forall x arg.
((Foo arg @a0 :: (Proxy @{arg} a0 -> *))
~ (Foo arg @a0 :: (Proxy @{arg} a0 -> *))) =>
Bar x
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the definition of data constructor ‘MkBar’
In the data declaration for ‘Bar’
T15076.hs:10:8: error:
• Cannot generalise type; skolem ‘a’ would escape its scope
if I tried to quantify (x0 :: a) in this type:
forall a (f :: forall (x :: a). Proxy @{a} x -> *).
Proxy @{Proxy @{a} x0 -> *} (f @x0) -> ()
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature:
foo :: forall (a :: Type) (f :: forall (x :: a). Proxy x -> Type).
Proxy f -> ()
T15076b.hs:8:8: error:
• Cannot generalise type; skolem ‘a’ would escape its scope
if I tried to quantify (x0 :: a) in this type:
forall a (f :: forall (x :: a). Proxy @{a} x -> *).
Proxy @{Proxy @{a} x0 -> *} (f @x0) -> ()
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature:
foo :: forall (a :: Type) (f :: forall (x :: a). Proxy x -> Type).
Proxy f -> ()
T15825.hs:14:31: error:
• Illegal type synonym family application ‘GHC.Types.Any
@k’ in instance:
X (a @(GHC.Types.Any @k))
T15825.hs:14:10: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (x0 :: k) in this type:
forall k (a :: C k). X (a @x0)
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the instance declaration for ‘X (a :: *)’
......@@ -60,3 +60,7 @@ test('T16418', normal, compile_fail, [''])
test('T17541', normal, compile_fail, [''])
test('T17541b', normal, compile_fail, [''])
test('T17131', normal, compile_fail, [''])
test('T14880', normal, compile_fail, [''])
test('T14880-2', normal, compile_fail, [''])
test('T15076', normal, compile_fail, [''])
test('T15076b', normal, compile_fail, [''])
T14040a.hs:34:8: error:
• Cannot apply expression of type ‘Sing wl
-> (forall y. p _0 'WeirdNil)
-> (forall z (x :: z) (xs :: WeirdList (WeirdList z)).
Sing x
-> Sing xs
-> p GHC.Types.Any xs
-> p GHC.Types.Any ('WeirdCons x xs))
-> p _1 wl’
to a visible type argument ‘(WeirdList z)’
• In the sixth argument of ‘pWeirdCons’, namely
‘(elimWeirdList @(WeirdList z) @xs @p xs pWeirdNil pWeirdCons)’
In the expression:
pWeirdCons
@z
@x
@xs
x
xs
(elimWeirdList @(WeirdList z) @xs @p xs pWeirdNil pWeirdCons)
In an equation for ‘elimWeirdList’:
elimWeirdList
(SWeirdCons (x :: Sing (x :: z))
(xs :: Sing (xs :: WeirdList (WeirdList z))))
pWeirdNil
pWeirdCons
= pWeirdCons
@z
@x
@xs
x
xs
(elimWeirdList @(WeirdList z) @xs @p xs pWeirdNil pWeirdCons)
T14040a.hs:21:18: error:
• Cannot generalise type; skolem ‘z’ would escape its scope
if I tried to quantify (_1 :: WeirdList z) in this type:
forall a1 (wl :: WeirdList a1)
(p :: forall x. x -> WeirdList x -> *).
Sing @(WeirdList a1) wl
-> (forall y. p @x0 _0 ('WeirdNil @x0))
-> (forall z (x :: z) (xs :: WeirdList (WeirdList z)).
Sing @z x
-> Sing @(WeirdList (WeirdList z)) xs
-> p @(WeirdList z) _1 xs
-> p @z _2 ('WeirdCons @z x xs))
-> p @a1 _3 wl
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature:
elimWeirdList :: forall (a :: Type)
(wl :: WeirdList a)
(p :: forall (x :: Type). x -> WeirdList x -> Type).
Sing wl
-> (forall (y :: Type). p _ WeirdNil)
-> (forall (z :: Type) (x :: z) (xs :: WeirdList (WeirdList z)).
Sing x -> Sing xs -> p _ xs -> p _ (WeirdCons x xs))
-> p _ wl
......@@ -75,7 +75,6 @@ test('T14058', [extra_files(['T14058.hs', 'T14058a.hs'])],
multimod_compile, ['T14058', '-v0'])
test('T14326', normal, compile, [''])
test('T14394', normal, ghci_script, ['T14394.script'])
test('T14552', normal, compile, [''])
test('T14498', normal, compile, [''])
test('T16682', [extra_files(['T16682.hs', 'T16682a.hs'])],
multimod_compile, ['T16682', '-v0 -fwarn-incomplete-patterns -fno-code'])
T14552.hs:22:9: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (aa0 :: k) in this type:
forall k (w :: k --> *). Exp a0 (F @k @(*) w aa0)
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the declaration for pattern synonym ‘FOO’
......@@ -46,3 +46,4 @@ test('T15685', normal, compile_fail, [''])
test('T15692', normal, compile, ['']) # It has -fdefer-type-errors inside
test('T15694', normal, compile_fail, [''])
test('T16900', normal, compile_fail, ['-fdiagnostics-show-caret'])
test('T14552', normal, compile_fail, [''])
T15795.hs:12:3: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (a0 :: k) in this type:
forall k (b :: k). T @k @a0 b
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the definition of data constructor ‘MkT’
In the data declaration for ‘T’
T15795a.hs:9:3: error:
• Cannot generalise type; skolem ‘u’ would escape its scope
if I tried to quantify (cat10 :: u) in this type:
forall u (a :: u). F @u @cat10 a
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the definition of data constructor ‘Prod’
In the data declaration for ‘F’
......@@ -204,8 +204,8 @@ test('T15817', normal, compile, [''])
test('T15874', normal, compile, [''])
test('T14887a', normal, compile, [''])
test('T14847', normal, compile, [''])
test('T15795', normal, compile, [''])
test('T15795a', normal, compile, [''])
test('T15795', normal, compile_fail, [''])
test('T15795a', normal, compile_fail, [''])
test('T16247', normal, compile_fail, [''])
test('T16247a', normal, compile_fail, [''])
test('KindVarOrder', normal, ghci_script, ['KindVarOrder.script'])
......
......@@ -685,7 +685,6 @@ test('UnlifNewUnify', normal, compile, [''])
test('UnliftedNewtypesLPFamily', normal, compile, [''])
test('UnliftedNewtypesDifficultUnification', normal, compile, [''])
test('T16832', normal, ghci_script, ['T16832.script'])
test('T16946', normal, compile, [''])
test('T16995', normal, compile, [''])
test('T17007', normal, compile, [''])
test('T17067', normal, compile, [''])
......
T14350.hs:59:15: error:
• Couldn't match expected type ‘Proxy a1
-> Apply (Apply c 'Proxy) (Apply g 'Proxy)’
with actual type ‘Sing (f @@ t0)’
• The function ‘applySing’ is applied to three arguments,
but its type ‘Sing f -> Sing t0 -> Sing (f @@ t0)’ has only two
In the expression: applySing f Proxy Proxy
In an equation for ‘dcomp’: dcomp f g x = applySing f Proxy Proxy
• Relevant bindings include
x :: Sing x (bound at T14350.hs:59:11)
g :: Sing g (bound at T14350.hs:59:9)
f :: Sing f (bound at T14350.hs:59:7)
dcomp :: Sing f
-> Sing g -> Sing x -> (c @@ 'Proxy) @@ (g @@ 'Proxy)
(bound at T14350.hs:59:1)
T14350.hs:59:27: error:
• Couldn't match expected type ‘Sing t0’
with actual type ‘Proxy a0’
• In the second argument of ‘applySing’, namely ‘Proxy’
In the expression: applySing f Proxy Proxy
In an equation for ‘dcomp’: dcomp f g x = applySing f Proxy Proxy
• Relevant bindings include
x :: Sing x (bound at T14350.hs:59:11)
g :: Sing g (bound at T14350.hs:59:9)
f :: Sing f (bound at T14350.hs:59:7)
dcomp :: Sing f
-> Sing g -> Sing x -> (c @@ 'Proxy) @@ (g @@ 'Proxy)
(bound at T14350.hs:59:1)
T14350.hs:49:10: error:
• Cannot generalise type; skolem ‘a’ would escape its scope
if I tried to quantify (x0 :: a) in this type:
forall a (b1 :: a ~> *)
(c :: forall (x :: a). Proxy @{a} x ~> ((@@) @{*} @{a} b1 x ~> *))
(f :: forall (x :: a) (y :: (@@) @{*} @{a} b1 x).
Proxy @{a} x
~> (Proxy @{Apply @a @(*) b1 x} y
~> (@@)
@{*}
@{Apply @a @(*) b1 x}
((@@)
@{Apply @a @(*) b1 x ~> *} @{Proxy @{a} x} (c @x) ('Proxy @{a} @x))
y))
(g :: forall (x :: a). Proxy @{a} x ~> (@@) @{*} @{a} b1 x)
(x :: a).
Sing
@(Proxy @{a} x0
~> (Proxy @{Apply @a @(*) b1 x0} y0
~> Apply
@(Apply @a @(*) b1 x0)
@(*)
(Apply
@(Proxy @{a} x0)
@(Apply @a @(*) b1 x0 ~> *)
(c @x0)
('Proxy @{a} @x0))
y0))
(f @x0 @y0)
-> Sing @(Proxy @{a} x1 ~> Apply @a @(*) b1 x1) (g @x1)
-> Sing @a x
-> (@@)
@{*}
@{Apply @a @(*) b1 x}
((@@)
@{Apply @a @(*) b1 x ~> *} @{Proxy @{a} x} (c @x) ('Proxy @{a} @x))
((@@)
@{Apply @a @(*) b1 x} @{Proxy @{a} x} (g @x) ('Proxy @{a} @x))
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature:
dcomp :: forall (a :: Type)
(b :: a ~> Type)
(c :: forall (x :: a). Proxy x ~> b @@ x ~> Type)
(f :: forall (x :: a) (y :: b @@ x).
Proxy x ~> Proxy y ~> c @@ ('Proxy :: Proxy x) @@ y)
(g :: forall (x :: a). Proxy x ~> b @@ x)
(x :: a).
Sing f
-> Sing g
-> Sing x -> c @@ ('Proxy :: Proxy x) @@ (g @@ ('Proxy :: Proxy x))
T16946.hs:11:9: error:
• Cannot generalise type; skolem ‘k’ would escape its scope
if I tried to quantify (y0 :: k) in this type:
forall k (c :: k -> k -> *)
(m :: forall (x :: k) (y :: k). c x y -> * -> *) a.
CatMonad @k c m =>
a -> m @y0 @y0 (Id @{k} @y0 c) a
(Indeed, I sometimes struggle even printing this correctly,
due to its ill-scoped nature.)
• In the type signature:
boom :: forall k
(c :: k -> k -> Type)
(m :: forall (x :: k) (y :: k). c x y -> Type -> Type)
a.
CatMonad c m => a -> m (Id c) a
......@@ -549,3 +549,4 @@ test('T17213', [extra_files(['T17213a.hs'])], multimod_compile_fail, ['T17213',
test('T17355', normal, compile_fail, [''])
test('T17360', normal, compile_fail, [''])
test('T17563', normal, compile_fail, [''])
test('T16946', normal, compile_fail, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment