diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2019-10-14 11:21:45 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-10-15 01:36:14 -0400 |
commit | 426b0ddc79890f80a8ceeef135371533f066b9ba (patch) | |
tree | a2eefaa3d05d2007090d36b8e82c781ed662a0e5 /compiler | |
parent | a2d3594ca173905502d3de2f4e25ef9e36d41906 (diff) | |
download | haskell-426b0ddc79890f80a8ceeef135371533f066b9ba.tar.gz |
Don't skip validity checks for built-in classes (#17355)
Issue #17355 occurred because the control flow for
`TcValidity.check_valid_inst_head` was structured in such a way that
whenever it checked a special, built-in class (like `Generic` or
`HasField`), it would skip the most important check of all:
`checkValidTypePats`, which rejects nonsense like this:
```hs
instance Generic (forall a. a)
```
This fixes the issue by carving out `checkValidTypePats` from
`check_valid_inst_head` so that `checkValidTypePats` is always
invoked. `check_valid_inst_head` has also been renamed to
`check_special_inst_head` to reflect its new purpose of _only_
checking for instances headed by special classes.
Fixes #17355.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/typecheck/TcValidity.hs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/typecheck/TcValidity.hs b/compiler/typecheck/TcValidity.hs index f97c9a7f27..e72aa7f7b0 100644 --- a/compiler/typecheck/TcValidity.hs +++ b/compiler/typecheck/TcValidity.hs @@ -1468,7 +1468,8 @@ checkValidInstHead ctxt clas cls_args = do { dflags <- getDynFlags ; is_boot <- tcIsHsBootOrSig ; is_sig <- tcIsHsig - ; check_valid_inst_head dflags is_boot is_sig ctxt clas cls_args + ; check_special_inst_head dflags is_boot is_sig ctxt clas cls_args + ; checkValidTypePats (classTyCon clas) cls_args } {- @@ -1496,10 +1497,10 @@ in hsig files, where `is_sig` is True. -} -check_valid_inst_head :: DynFlags -> Bool -> Bool - -> UserTypeCtxt -> Class -> [Type] -> TcM () +check_special_inst_head :: DynFlags -> Bool -> Bool + -> UserTypeCtxt -> Class -> [Type] -> TcM () -- Wow! There are a surprising number of ad-hoc special cases here. -check_valid_inst_head dflags is_boot is_sig ctxt clas cls_args +check_special_inst_head dflags is_boot is_sig ctxt clas cls_args -- If not in an hs-boot file, abstract classes cannot have instances | isAbstractClass clas @@ -1549,7 +1550,7 @@ check_valid_inst_head dflags is_boot is_sig ctxt clas cls_args = failWithTc (instTypeErr clas cls_args msg) | otherwise - = checkValidTypePats (classTyCon clas) cls_args + = pure () where clas_nm = getName clas ty_args = filterOutInvisibleTypes (classTyCon clas) cls_args |