diff --git a/compiler/types/Coercion.hs b/compiler/types/Coercion.hs index 3a3231d2700b6675952ca0ba0ba4613380c1250b..d0c5eeda696bb602db2f34497a64a155e5411eab 100644 --- a/compiler/types/Coercion.hs +++ b/compiler/types/Coercion.hs @@ -169,18 +169,22 @@ Defined here to avoid module loops. CoAxiom is loaded very early on. pprCoAxiom :: CoAxiom br -> SDoc pprCoAxiom ax@(CoAxiom { co_ax_branches = branches }) = hang (text "axiom" <+> ppr ax <+> dcolon) - 2 (vcat (map (ppr_co_ax_branch (const pprType) ax) $ fromBranches branches)) + 2 (vcat (map (ppr_co_ax_branch (\_ ty -> equals <+> pprType ty) ax) $ + fromBranches branches)) pprCoAxBranch :: CoAxiom br -> CoAxBranch -> SDoc pprCoAxBranch = ppr_co_ax_branch pprRhs where pprRhs fam_tc rhs - | Just (tycon, _) <- splitTyConApp_maybe rhs - , isDataFamilyTyCon fam_tc - = pprDataCons tycon + | isDataFamilyTyCon fam_tc + = empty -- Don't bother printing anything for the RHS of a data family + -- instance... | otherwise - = ppr rhs + = equals <+> ppr rhs + -- ...but for a type family instance, do print out the RHS, since + -- it might be needed to disambiguate between duplicate instances + -- (#14179) pprCoAxBranchHdr :: CoAxiom br -> BranchIndex -> SDoc pprCoAxBranchHdr ax index = pprCoAxBranch ax (coAxiomNthBranch ax index) @@ -194,8 +198,8 @@ ppr_co_ax_branch ppr_rhs , cab_rhs = rhs , cab_loc = loc }) = foldr1 (flip hangNotEmpty 2) - [ pprUserForAll (mkTyVarBinders Inferred (tvs ++ cvs)) - , pprTypeApp fam_tc lhs <+> equals <+> ppr_rhs fam_tc rhs + [ pprUserForAll (mkTyVarBinders Inferred (ee_tvs ++ cvs)) + , pprTypeApp fam_tc ee_lhs <+> ppr_rhs fam_tc rhs , text "-- Defined" <+> pprLoc loc ] where pprLoc loc @@ -206,6 +210,21 @@ ppr_co_ax_branch ppr_rhs = text "in" <+> quotes (ppr (nameModule name)) + (ee_tvs, ee_lhs) + | Just (tycon, tc_args) <- splitTyConApp_maybe rhs + , isDataFamilyTyCon fam_tc + = -- Eta-expand LHS types, because sometimes data family instances + -- are eta-reduced. + -- See Note [Eta reduction for data family axioms] in TcInstDecls. + let tc_tvs = tyConTyVars tycon + etad_tvs = dropList tc_args tc_tvs + etad_tys = mkTyVarTys etad_tvs + eta_expanded_tvs = tvs `chkAppend` etad_tvs + eta_expanded_lhs = lhs `chkAppend` etad_tys + in (eta_expanded_tvs, eta_expanded_lhs) + | otherwise + = (tvs, lhs) + {- %************************************************************************ %* * diff --git a/testsuite/tests/indexed-types/should_fail/Over.stderr b/testsuite/tests/indexed-types/should_fail/Over.stderr index 63b8b304b247f41863e711f57999f07ddd36c93c..3e0bc44b576c3611bfbbdbc76cfc40856d196f05 100644 --- a/testsuite/tests/indexed-types/should_fail/Over.stderr +++ b/testsuite/tests/indexed-types/should_fail/Over.stderr @@ -1,8 +1,8 @@ OverB.hs:7:15: error: Conflicting family instance declarations: - C [Int] [a] = CListList2 -- Defined at OverB.hs:7:15 - C [a] [Int] = C9ListList -- Defined at OverC.hs:7:15 + C [Int] [a] -- Defined at OverB.hs:7:15 + C [a] [Int] -- Defined at OverC.hs:7:15 OverB.hs:9:15: error: Conflicting family instance declarations: diff --git a/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr b/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr index 28c72df6e058fb8128ae7df7d7c3254b980e28e0..99a3377eb06116ee9108a1741046a09e4649e900 100644 --- a/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr +++ b/testsuite/tests/indexed-types/should_fail/OverDirectThisMod.stderr @@ -1,8 +1,8 @@ OverDirectThisModB.hs:7:15: error: Conflicting family instance declarations: - C [Int] [a] = CListList2 -- Defined at OverDirectThisModB.hs:7:15 - C [a] [Int] = C9ListList -- Defined at OverDirectThisModC.hs:10:15 + C [Int] [a] -- Defined at OverDirectThisModB.hs:7:15 + C [a] [Int] -- Defined at OverDirectThisModC.hs:10:15 OverDirectThisModB.hs:9:15: error: Conflicting family instance declarations: diff --git a/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr b/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr index 53c93e80ceba254e51f5f6d392ecfe61684676fe..af136704db670a5e668b3bade85c015c2d54161d 100644 --- a/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr +++ b/testsuite/tests/indexed-types/should_fail/OverIndirectThisMod.stderr @@ -1,10 +1,8 @@ OverIndirectThisModB.hs:7:15: error: Conflicting family instance declarations: - C [Int] [a] = OverIndirectThisModB.CListList2 - -- Defined at OverIndirectThisModB.hs:7:15 - C [a] [Int] = C9ListList - -- Defined at OverIndirectThisModD.hs:11:15 + C [Int] [a] -- Defined at OverIndirectThisModB.hs:7:15 + C [a] [Int] -- Defined at OverIndirectThisModD.hs:11:15 OverIndirectThisModB.hs:9:15: error: Conflicting family instance declarations: diff --git a/testsuite/tests/indexed-types/should_fail/SimpleFail11a.stderr b/testsuite/tests/indexed-types/should_fail/SimpleFail11a.stderr index d4670197609d3bc128d95e470a2c4460a8bc6574..41ed865dfb65888757d3736f87a7fbd2912f7152 100644 --- a/testsuite/tests/indexed-types/should_fail/SimpleFail11a.stderr +++ b/testsuite/tests/indexed-types/should_fail/SimpleFail11a.stderr @@ -1,10 +1,10 @@ -SimpleFail11a.hs:6:15: +SimpleFail11a.hs:6:15: error: Conflicting family instance declarations: - C9 Int Int = C9IntInt -- Defined at SimpleFail11a.hs:6:15 - C9 Int Int = C9IntInt2 -- Defined at SimpleFail11a.hs:8:15 + C9 Int Int -- Defined at SimpleFail11a.hs:6:15 + C9 Int Int -- Defined at SimpleFail11a.hs:8:15 -SimpleFail11a.hs:11:15: +SimpleFail11a.hs:11:15: error: Conflicting family instance declarations: D9 Int Int = Char -- Defined at SimpleFail11a.hs:11:15 D9 Int Int = Int -- Defined at SimpleFail11a.hs:13:15 diff --git a/testsuite/tests/indexed-types/should_fail/SimpleFail11b.stderr b/testsuite/tests/indexed-types/should_fail/SimpleFail11b.stderr index e40a3a6b4ee6fbac542bfd1d06d35d4aceb87737..bd05039dc8de7287b9c630ff18639ef922d60b63 100644 --- a/testsuite/tests/indexed-types/should_fail/SimpleFail11b.stderr +++ b/testsuite/tests/indexed-types/should_fail/SimpleFail11b.stderr @@ -1,10 +1,10 @@ -SimpleFail11b.hs:7:15: +SimpleFail11b.hs:7:15: error: Conflicting family instance declarations: - C9 [a] Int = C9ListInt -- Defined at SimpleFail11b.hs:7:15 - C9 [a] Int = C9ListInt2 -- Defined at SimpleFail11b.hs:9:15 + C9 [a] Int -- Defined at SimpleFail11b.hs:7:15 + C9 [a] Int -- Defined at SimpleFail11b.hs:9:15 -SimpleFail11b.hs:13:15: +SimpleFail11b.hs:13:15: error: Conflicting family instance declarations: D9 [a] Int = [a] -- Defined at SimpleFail11b.hs:13:15 D9 [a] Int = Maybe a -- Defined at SimpleFail11b.hs:15:15 diff --git a/testsuite/tests/indexed-types/should_fail/SimpleFail11c.stderr b/testsuite/tests/indexed-types/should_fail/SimpleFail11c.stderr index d4a1bb4f3002a7ba62c81ad65f94d33da3a1d647..cbb457933bfa018d67350e21fda7bb840ce7edc6 100644 --- a/testsuite/tests/indexed-types/should_fail/SimpleFail11c.stderr +++ b/testsuite/tests/indexed-types/should_fail/SimpleFail11c.stderr @@ -1,10 +1,10 @@ -SimpleFail11c.hs:7:15: +SimpleFail11c.hs:7:15: error: Conflicting family instance declarations: - C9 [a] Int = C9ListInt -- Defined at SimpleFail11c.hs:7:15 - C9 [Int] Int = C9ListInt2 -- Defined at SimpleFail11c.hs:9:15 + C9 [a] Int -- Defined at SimpleFail11c.hs:7:15 + C9 [Int] Int -- Defined at SimpleFail11c.hs:9:15 -SimpleFail11c.hs:13:15: +SimpleFail11c.hs:13:15: error: Conflicting family instance declarations: D9 [a] Int = [a] -- Defined at SimpleFail11c.hs:13:15 D9 [Int] Int = [Bool] -- Defined at SimpleFail11c.hs:15:15 diff --git a/testsuite/tests/indexed-types/should_fail/SimpleFail11d.stderr b/testsuite/tests/indexed-types/should_fail/SimpleFail11d.stderr index cdd8afda9614e0db9e385009e85b8beca7a5056d..48d3c33fef557ef4d0e10d1d43c493e9175cff43 100644 --- a/testsuite/tests/indexed-types/should_fail/SimpleFail11d.stderr +++ b/testsuite/tests/indexed-types/should_fail/SimpleFail11d.stderr @@ -1,5 +1,5 @@ -SimpleFail11d.hs:8:15: +SimpleFail11d.hs:8:15: error: Conflicting family instance declarations: - C9 [Int] [a] = C9ListList2 -- Defined at SimpleFail11d.hs:8:15 - C9 [a] [Int] = C9ListList -- Defined at SimpleFail11d.hs:10:15 + C9 [Int] [a] -- Defined at SimpleFail11d.hs:8:15 + C9 [a] [Int] -- Defined at SimpleFail11d.hs:10:15 diff --git a/testsuite/tests/indexed-types/should_fail/SimpleFail2b.stderr b/testsuite/tests/indexed-types/should_fail/SimpleFail2b.stderr index bb0aaca16ca92fab01f27eb78599b4b843ebbca7..88fdfe127c57844686fbc0718d649449c1c5e35a 100644 --- a/testsuite/tests/indexed-types/should_fail/SimpleFail2b.stderr +++ b/testsuite/tests/indexed-types/should_fail/SimpleFail2b.stderr @@ -1,5 +1,5 @@ -SimpleFail2b.hs:9:11: +SimpleFail2b.hs:9:11: error: Conflicting family instance declarations: - Sd Int = SdC1 Char -- Defined at SimpleFail2b.hs:9:11 - Sd Int = SdC2 Char -- Defined at SimpleFail2b.hs:10:11 + Sd Int -- Defined at SimpleFail2b.hs:9:11 + Sd Int -- Defined at SimpleFail2b.hs:10:11 diff --git a/testsuite/tests/indexed-types/should_fail/T14179.hs b/testsuite/tests/indexed-types/should_fail/T14179.hs new file mode 100644 index 0000000000000000000000000000000000000000..60c8a94c393a3b20e83284cb0dacbb43de6f635c --- /dev/null +++ b/testsuite/tests/indexed-types/should_fail/T14179.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE GADTs #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE TypeFamilies #-} +module T14179 where + +data family Foo1 a +data instance Foo1 a +data instance Foo1 a + +data family Foo2 :: k -> * +data instance Foo2 :: * -> * +data instance Foo2 :: * -> * + +data family Foo3 a +data instance Foo3 [a] where + Foo3a :: Foo3 [Int] + Foo3b :: Foo3 [Bool] +data instance Foo3 [a] where + Foo3c :: Foo3 [a] + Foo3d :: Foo3 [Char] diff --git a/testsuite/tests/indexed-types/should_fail/T14179.stderr b/testsuite/tests/indexed-types/should_fail/T14179.stderr new file mode 100644 index 0000000000000000000000000000000000000000..38d77f1cca00ede7b3a2ab91419a5c5fcd235700 --- /dev/null +++ b/testsuite/tests/indexed-types/should_fail/T14179.stderr @@ -0,0 +1,15 @@ + +T14179.hs:7:15: error: + Conflicting family instance declarations: + Foo1 a -- Defined at T14179.hs:7:15 + Foo1 a -- Defined at T14179.hs:8:15 + +T14179.hs:11:15: error: + Conflicting family instance declarations: + Foo2 a -- Defined at T14179.hs:11:15 + Foo2 a -- Defined at T14179.hs:12:15 + +T14179.hs:15:15: error: + Conflicting family instance declarations: + Foo3 [a] -- Defined at T14179.hs:15:15 + Foo3 [a] -- Defined at T14179.hs:18:15 diff --git a/testsuite/tests/indexed-types/should_fail/T2334A.stderr b/testsuite/tests/indexed-types/should_fail/T2334A.stderr index 7b7d265d6128a801f5b9ee25710b28203f812def..a5bc0a0e7861870681a58f1aff55509e16608226 100644 --- a/testsuite/tests/indexed-types/should_fail/T2334A.stderr +++ b/testsuite/tests/indexed-types/should_fail/T2334A.stderr @@ -1,17 +1,17 @@ -T2334A.hs:9:26: - The constructor of a newtype must have exactly one field - but ‘F’ has two - In the definition of data constructor ‘F’ - In the newtype instance declaration for ‘F’ +T2334A.hs:9:26: error: + • The constructor of a newtype must have exactly one field + but ‘F’ has two + • In the definition of data constructor ‘F’ + In the newtype instance declaration for ‘F’ -T2334A.hs:10:27: - The constructor of a newtype must have exactly one field - but ‘H’ has none - In the definition of data constructor ‘H’ - In the newtype instance declaration for ‘F’ +T2334A.hs:10:27: error: + • The constructor of a newtype must have exactly one field + but ‘H’ has none + • In the definition of data constructor ‘H’ + In the newtype instance declaration for ‘F’ -T2334A.hs:12:15: +T2334A.hs:12:15: error: Conflicting family instance declarations: - F Bool = K1 -- Defined at T2334A.hs:12:15 - F Bool = K2 -- Defined at T2334A.hs:13:15 + F Bool -- Defined at T2334A.hs:12:15 + F Bool -- Defined at T2334A.hs:13:15 diff --git a/testsuite/tests/indexed-types/should_fail/T9371.stderr b/testsuite/tests/indexed-types/should_fail/T9371.stderr index 729ee3a8c0925f3a84903350145f0fcdebd8942d..9207ac5ae2d2311eb8cda3e0a9d40dc2720cb603 100644 --- a/testsuite/tests/indexed-types/should_fail/T9371.stderr +++ b/testsuite/tests/indexed-types/should_fail/T9371.stderr @@ -1,5 +1,5 @@ -T9371.hs:14:10: +T9371.hs:14:10: error: Conflicting family instance declarations: - D = D1 (Either x ()) -- Defined at T9371.hs:14:10 - D (x, y) = D2 (x, y) -- Defined at T9371.hs:18:10 + D x -- Defined at T9371.hs:14:10 + D (x, y) -- Defined at T9371.hs:18:10 diff --git a/testsuite/tests/indexed-types/should_fail/all.T b/testsuite/tests/indexed-types/should_fail/all.T index 61025d6c928b0e2557d12ee7b50eeafcbe8bd35d..80ea5dafa9c282576af938f1002e31608833b022 100644 --- a/testsuite/tests/indexed-types/should_fail/all.T +++ b/testsuite/tests/indexed-types/should_fail/all.T @@ -140,5 +140,6 @@ test('T13972', normal, compile_fail, ['']) test('T14033', normal, compile_fail, ['']) test('T14045a', normal, compile_fail, ['']) test('T14175', normal, compile_fail, ['']) +test('T14179', normal, compile_fail, ['']) test('T14369', normal, compile_fail, ['']) test('T15172', normal, compile_fail, ['']) diff --git a/testsuite/tests/partial-sigs/should_compile/DataFamilyInstanceLHS.stderr b/testsuite/tests/partial-sigs/should_compile/DataFamilyInstanceLHS.stderr index 4a94901ab52500d121b27cb9b647a8f6a8f4a590..4e0975eb3ec3e0124dc987697f7ba543abf1cea0 100644 --- a/testsuite/tests/partial-sigs/should_compile/DataFamilyInstanceLHS.stderr +++ b/testsuite/tests/partial-sigs/should_compile/DataFamilyInstanceLHS.stderr @@ -15,7 +15,7 @@ TYPE CONSTRUCTORS data family Sing (a :: k) COERCION AXIOMS axiom DataFamilyInstanceLHS.D:R:SingMyKind_0 :: - Sing = DataFamilyInstanceLHS.R:SingMyKind_ + Sing _ = DataFamilyInstanceLHS.R:SingMyKind_ -- Defined at DataFamilyInstanceLHS.hs:8:15 FAMILY INSTANCES data instance Sing diff --git a/testsuite/tests/partial-sigs/should_compile/NamedWildcardInDataFamilyInstanceLHS.stderr b/testsuite/tests/partial-sigs/should_compile/NamedWildcardInDataFamilyInstanceLHS.stderr index c3c383bb72a380070bac8599559443742588dd62..8fae725e61bb9697f2286eb5d5429df006a0ee41 100644 --- a/testsuite/tests/partial-sigs/should_compile/NamedWildcardInDataFamilyInstanceLHS.stderr +++ b/testsuite/tests/partial-sigs/should_compile/NamedWildcardInDataFamilyInstanceLHS.stderr @@ -14,7 +14,7 @@ TYPE CONSTRUCTORS data family Sing (a :: k) COERCION AXIOMS axiom NamedWildcardInDataFamilyInstanceLHS.D:R:SingMyKind_a0 :: - Sing = NamedWildcardInDataFamilyInstanceLHS.R:SingMyKind_a + Sing _a = NamedWildcardInDataFamilyInstanceLHS.R:SingMyKind_a -- Defined at NamedWildcardInDataFamilyInstanceLHS.hs:8:15 FAMILY INSTANCES data instance Sing