Skip to content

Commit

Permalink
TC: Fix missing location in mapping patterns
Browse files Browse the repository at this point in the history
Reported in PR 834
  • Loading branch information
Alasdair committed Dec 17, 2024
1 parent 52d292a commit 93bf500
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/type_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4194,7 +4194,9 @@ and bind_mpat allow_unknown other_env env (MP_aux (mpat_aux, (l, uannot)) as mpa
| _ -> Reporting.unreachable l __POS__ "unifying mapping type, expanded synonyms to non-mapping type!"
end
| MP_app (other, mpats) when Env.is_mapping other env ->
bind_mpat allow_unknown other_env env (MP_aux (MP_app (other, [mk_mpat (MP_tuple mpats)]), (l, uannot))) typ
bind_mpat allow_unknown other_env env
(MP_aux (MP_app (other, [mk_mpat ~loc:l (MP_tuple mpats)]), (l, uannot)))
typ
| MP_app (f, _) when not (Env.is_union_constructor f env || Env.is_mapping f env) ->
typ_error l (string_of_id f ^ " is not a union constructor or mapping in mapping-pattern " ^ string_of_mpat mpat)
| MP_as (mpat, id) ->
Expand Down
5 changes: 5 additions & 0 deletions test/typecheck/fail/mp_tuple_loc.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Type error:
fail/mp_tuple_loc.sail:9.9-24:
9 | () <-> foo((), (), ()),
 | ^-------------^
 | Tuple mapping-pattern and tuple type have different length
16 changes: 16 additions & 0 deletions test/typecheck/fail/mp_tuple_loc.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

enum E = A

mapping foo : (unit, unit) <-> E = {
((), ()) <-> A,
}

mapping bar : unit <-> E = {
() <-> foo((), (), ()),
}

val main : unit -> unit

function main() = {
let _ : E = bar();
}

0 comments on commit 93bf500

Please sign in to comment.