From 8b0433f9a80007b0f0befae2fb5450975f711fe3 Mon Sep 17 00:00:00 2001 From: Troels Henriksen Date: Sun, 22 Dec 2024 21:48:24 +0100 Subject: [PATCH] Fix more error messages. --- src/Language/Futhark/TypeChecker/Constraints.hs | 9 +++++++++ tests/sumtypes/sumtype46.fut | 2 +- tests/sumtypes/sumtype48.fut | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Language/Futhark/TypeChecker/Constraints.hs b/src/Language/Futhark/TypeChecker/Constraints.hs index 5a4586ce25..8b8355c12a 100644 --- a/src/Language/Futhark/TypeChecker/Constraints.hs +++ b/src/Language/Futhark/TypeChecker/Constraints.hs @@ -373,6 +373,14 @@ cannotUnify reason notes bcs t1 t2 = do "Latter:" <+> pretty latter' ] +unsharedConstructorsMsg :: M.Map Name t -> M.Map Name t -> Doc a +unsharedConstructorsMsg cs1 cs2 = + "Unshared constructors:" <+> commasep (map (("#" <>) . pretty) missing) <> "." + where + missing = + filter (`notElem` M.keys cs1) (M.keys cs2) + ++ filter (`notElem` M.keys cs2) (M.keys cs1) + -- Precondition: 'v' is currently flexible. subTyVar :: Reason -> BreadCrumbs -> VName -> Type -> SolveM () subTyVar reason bcs v t = do @@ -412,6 +420,7 @@ subTyVar reason bcs v t = do indent 2 (stack (map (("#" <>) . pretty) (M.keys cs1))) "with type with constructors" indent 2 (stack (map (("#" <>) . pretty) (M.keys cs2))) + unsharedConstructorsMsg cs1 cs2 ( Just (Right (TyVarUnsol (TyVarSum _ cs1))), _ ) -> diff --git a/tests/sumtypes/sumtype46.fut b/tests/sumtypes/sumtype46.fut index dac4e4671f..a56af88750 100644 --- a/tests/sumtypes/sumtype46.fut +++ b/tests/sumtypes/sumtype46.fut @@ -1,5 +1,5 @@ -- == --- error: cannot match +-- error: 0 constructor arguments type t = #foo f64 diff --git a/tests/sumtypes/sumtype48.fut b/tests/sumtypes/sumtype48.fut index ad614f03cf..6c184e9239 100644 --- a/tests/sumtypes/sumtype48.fut +++ b/tests/sumtypes/sumtype48.fut @@ -3,4 +3,4 @@ type t = #foo | #bar -let f b : t = if b then #foo else #baar +def f b : t = if b then #foo else #baar