diff options
author | sheaf <sam.derbyshire@gmail.com> | 2022-01-26 14:24:48 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-02-08 05:27:25 -0500 |
commit | a9355e84480e421a22fee57d6ee24d9ec059e128 (patch) | |
tree | 7994b81532b131db79c56a25c17d6ee34e1f63dd /compiler/GHC/Tc | |
parent | ff867c460db9cfc43f5697c8e582f8c1ea4bd572 (diff) | |
download | haskell-a9355e84480e421a22fee57d6ee24d9ec059e128.tar.gz |
Allow HasField in quantified constraints
We perform validity checking on user-written HasField instances,
for example to disallow:
data Foo a = Foo { fld :: Int }
instance HasField "fld" (Foo a) Bool
However, these checks were also being made on quantified constraints,
e.g.
data Bar where
Bar :: (forall a. HasField s (Foo a) Int) => Proxy s -> Bar
This patch simply skips validity checking for quantified constraints,
in line with what we already do for equality constraints such as
Coercible.
Fixes #20989
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r-- | compiler/GHC/Tc/Validity.hs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/GHC/Tc/Validity.hs b/compiler/GHC/Tc/Validity.hs index 9d6a05c7aa..cad2ea1796 100644 --- a/compiler/GHC/Tc/Validity.hs +++ b/compiler/GHC/Tc/Validity.hs @@ -1417,6 +1417,10 @@ check_special_inst_head dflags is_boot is_sig ctxt clas cls_args ; when (safeInferOn dflags) (recordUnsafeInfer emptyMessages) } | clas_nm == hasFieldClassName + , not quantified_constraint + -- Don't do any validity checking for HasField contexts + -- inside quantified constraints (#20989): the validity checks + -- only apply to user-written instances. = checkHasFieldInst clas cls_args | isCTupleClass clas |