Sjoerd Visscher pushed to branch wip/T18570 at Glasgow Haskell Compiler / GHC
Commits:
-
f05d68b2
by Sjoerd Visscher at 2025-06-27T21:00:38+02:00
4 changed files:
- compiler/GHC/Tc/TyCl.hs
- testsuite/tests/typecheck/should_fail/CommonFieldTypeMismatch.stderr
- testsuite/tests/typecheck/should_fail/T12083a.stderr
- testsuite/tests/typecheck/should_fail/T9739.stderr
Changes:
| ... | ... | @@ -4787,6 +4787,7 @@ checkValidTyCl tc |
| 4787 | 4787 | = setSrcSpan (getSrcSpan tc) $
|
| 4788 | 4788 | addTyConCtxt tc $
|
| 4789 | 4789 | recoverM recovery_code $
|
| 4790 | + checkNoErrs $
|
|
| 4790 | 4791 | do { traceTc "Starting validity for tycon" (ppr tc)
|
| 4791 | 4792 | ; checkValidTyCon tc
|
| 4792 | 4793 | ; checkTyConConsistentWithBoot tc -- See Note [TyCon boot consistency checking]
|
| ... | ... | @@ -4991,7 +4992,7 @@ checkValidTyCon tc |
| 4991 | 4992 | check_fields ((label, con1) :| other_fields)
|
| 4992 | 4993 | -- These fields all have the same name, but are from
|
| 4993 | 4994 | -- different constructors in the data type
|
| 4994 | - = recoverM (return ()) $ mapM_ checkOne other_fields
|
|
| 4995 | + = mapM_ checkOne other_fields
|
|
| 4995 | 4996 | -- Check that all the fields in the group have the same type
|
| 4996 | 4997 | -- NB: this check assumes that all the constructors of a given
|
| 4997 | 4998 | -- data type use the same type variables
|
| ... | ... | @@ -5001,8 +5002,10 @@ checkValidTyCon tc |
| 5001 | 5002 | lbl = flLabel label
|
| 5002 | 5003 | |
| 5003 | 5004 | checkOne (_, con2) -- Do it both ways to ensure they are structurally identical
|
| 5004 | - = do { checkFieldCompat lbl con1 con2 res1 res2 fty1 fty2
|
|
| 5005 | - ; checkFieldCompat lbl con2 con1 res2 res1 fty2 fty1 }
|
|
| 5005 | + = do { ((), no_errs) <- askNoErrs $
|
|
| 5006 | + checkFieldCompat lbl con1 con2 res1 res2 fty1 fty2
|
|
| 5007 | + ; when no_errs $
|
|
| 5008 | + checkFieldCompat lbl con2 con1 res2 res1 fty2 fty1 }
|
|
| 5006 | 5009 | where
|
| 5007 | 5010 | res2 = dataConOrigResTy con2
|
| 5008 | 5011 | fty2 = dataConFieldType con2 lbl
|
| ... | ... | @@ -5029,8 +5032,10 @@ checkPartialRecordField all_cons fld |
| 5029 | 5032 | checkFieldCompat :: FieldLabelString -> DataCon -> DataCon
|
| 5030 | 5033 | -> Type -> Type -> Type -> Type -> TcM ()
|
| 5031 | 5034 | checkFieldCompat fld con1 con2 res1 res2 fty1 fty2
|
| 5032 | - = do { checkTc (isJust mb_subst1) (TcRnCommonFieldResultTypeMismatch con1 con2 fld)
|
|
| 5033 | - ; checkTc (isJust mb_subst2) (TcRnCommonFieldTypeMismatch con1 con2 fld) }
|
|
| 5035 | + = if isNothing mb_subst1
|
|
| 5036 | + then addErrTc $ TcRnCommonFieldResultTypeMismatch con1 con2 fld
|
|
| 5037 | + else when (isNothing mb_subst2) $
|
|
| 5038 | + addErrTc $ TcRnCommonFieldTypeMismatch con1 con2 fld
|
|
| 5034 | 5039 | where
|
| 5035 | 5040 | mb_subst1 = tcMatchTy res1 res2
|
| 5036 | 5041 | mb_subst2 = tcMatchTyX (expectJust mb_subst1) fty1 fty2
|
| ... | ... | @@ -2,10 +2,3 @@ CommonFieldTypeMismatch.hs:3:1: error: [GHC-91827] |
| 2 | 2 | • Constructors A1 and A2 give different types for field ‘fld’
|
| 3 | 3 | • In the data type declaration for ‘A’
|
| 4 | 4 | |
| 5 | -CommonFieldTypeMismatch.hs:4:8: error: [GHC-83865]
|
|
| 6 | - • Couldn't match type ‘[Char]’ with ‘Int’
|
|
| 7 | - Expected: Int
|
|
| 8 | - Actual: String
|
|
| 9 | - • In the expression: fld
|
|
| 10 | - In an equation for ‘fld’: fld A2 {fld = fld} = fld
|
|
| 11 | - |
| 1 | - |
|
| 2 | 1 | T12083a.hs:6:1: error: [GHC-91510]
|
| 3 | 2 | • Illegal qualified type: Num a => a
|
| 4 | 3 | • In the type synonym declaration for ‘Constrd’
|
| ... | ... | @@ -12,3 +11,20 @@ T12083a.hs:10:26: error: [GHC-25709] |
| 12 | 11 | In the data type declaration for ‘ExistentiallyLost’
|
| 13 | 12 | Suggested fix:
|
| 14 | 13 | Enable any of the following extensions: ‘ExistentialQuantification’ or ‘GADTs’
|
| 14 | + |
|
| 15 | +T12083a.hs:15:5: error: [GHC-27958]
|
|
| 16 | + • Could not deduce ‘ATF1 (p0, p1) ~ p0’
|
|
| 17 | + arising from a superclass required to satisfy ‘TC (p0, p1)’,
|
|
| 18 | + arising from a type ambiguity check for
|
|
| 19 | + the type signature for ‘uie_handlers’
|
|
| 20 | + from the context: TC u
|
|
| 21 | + bound by the type signature for:
|
|
| 22 | + uie_handlers :: forall u. TC u => ADT Int
|
|
| 23 | + at T12083a.hs:15:5-28
|
|
| 24 | + The type variables ‘p0’, ‘p1’ are ambiguous
|
|
| 25 | + • In the ambiguity check for ‘uie_handlers’
|
|
| 26 | + To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
|
|
| 27 | + When checking the class method:
|
|
| 28 | + uie_handlers :: forall u. TC u => ADT Int
|
|
| 29 | + In the class declaration for ‘TC’
|
|
| 30 | + |
| 1 | - |
|
| 2 | 1 | T9739.hs:4:1: error: [GHC-29210]
|
| 3 | 2 | • Superclass cycle for ‘Class1’
|
| 4 | 3 | one of whose superclasses is ‘Class3’
|
| ... | ... | @@ -7,6 +6,22 @@ T9739.hs:4:1: error: [GHC-29210] |
| 7 | 6 | Suggested fix:
|
| 8 | 7 | Perhaps you intended to use the ‘UndecidableSuperClasses’ extension
|
| 9 | 8 | |
| 9 | +T9739.hs:7:3: error: [GHC-39999]
|
|
| 10 | + • Could not deduce ‘Class1 t0’
|
|
| 11 | + arising from a superclass required to satisfy ‘Class3 t0’,
|
|
| 12 | + arising from a type ambiguity check for
|
|
| 13 | + the type signature for ‘class2’
|
|
| 14 | + from the context: (Class2 t a, Class3 t)
|
|
| 15 | + bound by the type signature for:
|
|
| 16 | + class2 :: forall t a m. (Class2 t a, Class3 t) => a -> m
|
|
| 17 | + at T9739.hs:7:3-32
|
|
| 18 | + The type variable ‘t0’ is ambiguous
|
|
| 19 | + • In the ambiguity check for ‘class2’
|
|
| 20 | + To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
|
|
| 21 | + When checking the class method:
|
|
| 22 | + class2 :: forall t a m. (Class2 t a, Class3 t) => a -> m
|
|
| 23 | + In the class declaration for ‘Class2’
|
|
| 24 | + |
|
| 10 | 25 | T9739.hs:9:1: error: [GHC-29210]
|
| 11 | 26 | • Superclass cycle for ‘Class3’
|
| 12 | 27 | one of whose superclasses is ‘Class1’
|
| ... | ... | @@ -14,3 +29,4 @@ T9739.hs:9:1: error: [GHC-29210] |
| 14 | 29 | • In the class declaration for ‘Class3’
|
| 15 | 30 | Suggested fix:
|
| 16 | 31 | Perhaps you intended to use the ‘UndecidableSuperClasses’ extension
|
| 32 | + |