
Sjoerd Visscher pushed to branch wip/T18570 at Glasgow Haskell Compiler / GHC Commits: cd2daa3b by Sjoerd Visscher at 2025-06-27T16:56:17+02:00 Fix field type mismatch error handling - - - - - 2 changed files: - compiler/GHC/Tc/TyCl.hs - testsuite/tests/typecheck/should_fail/CommonFieldTypeMismatch.stderr Changes: ===================================== compiler/GHC/Tc/TyCl.hs ===================================== @@ -4787,6 +4787,7 @@ checkValidTyCl tc = setSrcSpan (getSrcSpan tc) $ addTyConCtxt tc $ recoverM recovery_code $ + checkNoErrs $ do { traceTc "Starting validity for tycon" (ppr tc) ; checkValidTyCon tc ; checkTyConConsistentWithBoot tc -- See Note [TyCon boot consistency checking] @@ -4991,7 +4992,7 @@ checkValidTyCon tc check_fields ((label, con1) :| other_fields) -- These fields all have the same name, but are from -- different constructors in the data type - = recoverM (return ()) $ mapM_ checkOne other_fields + = mapM_ checkOne other_fields -- Check that all the fields in the group have the same type -- NB: this check assumes that all the constructors of a given -- data type use the same type variables @@ -5001,8 +5002,10 @@ checkValidTyCon tc lbl = flLabel label checkOne (_, con2) -- Do it both ways to ensure they are structurally identical - = do { checkFieldCompat lbl con1 con2 res1 res2 fty1 fty2 - ; checkFieldCompat lbl con2 con1 res2 res1 fty2 fty1 } + = do { ((), no_errs) <- askNoErrs $ + checkFieldCompat lbl con1 con2 res1 res2 fty1 fty2 + ; when no_errs $ + checkFieldCompat lbl con2 con1 res2 res1 fty2 fty1 } where res2 = dataConOrigResTy con2 fty2 = dataConFieldType con2 lbl @@ -5029,8 +5032,8 @@ checkPartialRecordField all_cons fld checkFieldCompat :: FieldLabelString -> DataCon -> DataCon -> Type -> Type -> Type -> Type -> TcM () checkFieldCompat fld con1 con2 res1 res2 fty1 fty2 - = do { checkTc (isJust mb_subst1) (TcRnCommonFieldResultTypeMismatch con1 con2 fld) - ; checkTc (isJust mb_subst2) (TcRnCommonFieldTypeMismatch con1 con2 fld) } + = do { unless (isJust mb_subst1) (addErrTc $ TcRnCommonFieldResultTypeMismatch con1 con2 fld) + ; unless (isJust mb_subst2) (addErrTc $ TcRnCommonFieldTypeMismatch con1 con2 fld) } where mb_subst1 = tcMatchTy res1 res2 mb_subst2 = tcMatchTyX (expectJust mb_subst1) fty1 fty2 ===================================== testsuite/tests/typecheck/should_fail/CommonFieldTypeMismatch.stderr ===================================== @@ -2,10 +2,3 @@ CommonFieldTypeMismatch.hs:3:1: error: [GHC-91827] • Constructors A1 and A2 give different types for field ‘fld’ • In the data type declaration for ‘A’ -CommonFieldTypeMismatch.hs:4:8: error: [GHC-83865] - • Couldn't match type ‘[Char]’ with ‘Int’ - Expected: Int - Actual: String - • In the expression: fld - In an equation for ‘fld’: fld A2 {fld = fld} = fld - View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cd2daa3b3c16af0e44d82c65e632fc21... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cd2daa3b3c16af0e44d82c65e632fc21... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Sjoerd Visscher (@trac-sjoerd_visscher)