Skip to content

Commit

Permalink
Fix more error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Dec 22, 2024
1 parent d068577 commit 8b0433f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Language/Futhark/TypeChecker/Constraints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))),
_
) ->
Expand Down
2 changes: 1 addition & 1 deletion tests/sumtypes/sumtype46.fut
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- ==
-- error: cannot match
-- error: 0 constructor arguments

type t = #foo f64

Expand Down
2 changes: 1 addition & 1 deletion tests/sumtypes/sumtype48.fut
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8b0433f

Please sign in to comment.