Skip to content

Commit b3c4c14

Browse files
committed
rustboot: Emit an error message instead of asserting on a type-param mismatch in tag constructors in patterns
1 parent 3d0da75 commit b3c4c14

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/boot/me/resolve.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,12 @@ let pattern_resolving_visitor
768768
end
769769
in
770770

771-
let resolve_arm { node = arm; id = _ } =
771+
let resolve_arm { node = arm; id = id } =
772772
match fst arm with
773773
Ast.PAT_tag (lval, pats) ->
774774
let lval_nm = lval_to_name lval in
775775
let lval_id = lval_base_id lval in
776-
let tag_ctor_id = (lval_item cx lval).id in
776+
let tag_ctor_id = (lval_item ~node_id:id cx lval).id in
777777
if defn_id_is_item cx tag_ctor_id
778778

779779
(* FIXME (issue #76): we should actually check here that the

src/boot/me/semant.ml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ let exports_permit (view:Ast.mod_view) (ident:Ast.ident) : bool =
14061406
;;
14071407

14081408
(* NB: this will fail if lval is not an item. *)
1409-
let rec lval_item (cx:ctxt) (lval:Ast.lval) : Ast.mod_item =
1409+
let rec lval_item ?node_id:node_id (cx:ctxt) (lval:Ast.lval) : Ast.mod_item =
14101410
match lval with
14111411
Ast.LVAL_base _ ->
14121412
let defn_id = lval_base_defn_id cx lval in
@@ -1429,9 +1429,13 @@ let rec lval_item (cx:ctxt) (lval:Ast.lval) : Ast.mod_item =
14291429
in
14301430
match htab_search items i with
14311431
| Some sub when exports_permit view i ->
1432-
assert
1433-
((Array.length sub.node.Ast.decl_params) =
1434-
(Array.length args));
1432+
if Array.length sub.node.Ast.decl_params !=
1433+
(Array.length args) then
1434+
err node_id
1435+
"%a has %d type-params but %d given"
1436+
Ast.sprintf_mod_item ("", sub)
1437+
(Array.length sub.node.Ast.decl_params)
1438+
(Array.length args);
14351439
check_concrete base_item.node.Ast.decl_params sub
14361440
| _ -> err (Some (lval_base_id lval))
14371441
"unknown module item '%s'" i

0 commit comments

Comments
 (0)