@@ -868,56 +868,57 @@ let resolve_recursion
868
868
869
869
let pattern_resolving_visitor
870
870
(cx :ctxt )
871
- (scopes :scope list ref )
872
871
(inner :Walk.visitor ) : Walk.visitor =
873
872
874
- let not_tag_ctor (nid :Ast.name identified ) : unit =
875
- err (Some nid.id) " '%s' is not a tag constructor"
876
- (string_of_name nid.node)
873
+ let not_tag_ctor nm id : unit =
874
+ err (Some id) " '%s' is not a tag constructor" (string_of_name nm)
877
875
in
878
876
879
877
let resolve_pat_tag
880
- (namei :Ast.name identified )
878
+ (name :Ast.name )
879
+ (id :node_id )
881
880
(pats :Ast.pat array )
882
881
(tag_ctor_id :node_id )
883
882
: unit =
884
883
884
+ (* NB this isn't really the proper tag type, since we aren't applying any
885
+ * type parameters from the tag constructor in the pattern, but since we
886
+ * are only looking at the fact that it's a tag-like type at all, and
887
+ * asking for its arity, it doesn't matter that the possibly parametric
888
+ * tag type has its parameters unbound here. *)
885
889
let tag_ty =
886
- fn_output_ty
887
- (Hashtbl. find cx.ctxt_all_item_types tag_ctor_id)
890
+ fn_output_ty (Hashtbl. find cx.ctxt_all_item_types tag_ctor_id)
888
891
in
889
892
begin
890
893
match tag_ty with
891
894
Ast. TY_tag _
892
895
| Ast. TY_iso _ ->
893
- let tag_ty_tup = tag_or_iso_ty_tup_by_name tag_ty namei.node in
896
+ let tag_ty_tup = tag_or_iso_ty_tup_by_name tag_ty name in
894
897
let arity = Array. length tag_ty_tup in
895
- if (Array. length pats) == arity
896
- then Hashtbl. add cx.ctxt_pattag_to_item namei.id tag_ctor_id
897
- else err (Some namei.id)
898
- " tag pattern '%s' with wrong number of components"
899
- (string_of_name namei.node)
900
- | _ -> not_tag_ctor namei
898
+ if (Array. length pats) != arity
899
+ then
900
+ err (Some id)
901
+ " tag pattern '%s' with wrong number of components"
902
+ (string_of_name name)
903
+ else ()
904
+ | _ -> not_tag_ctor name id
901
905
end
902
906
in
903
907
904
908
let resolve_arm { node = arm } =
905
909
match fst arm with
906
- Ast. PAT_tag (namei , pats ) ->
907
- begin
908
- match lookup_by_name cx ! scopes namei.node with
909
- None ->
910
- err (Some namei.id) " unresolved tag constructor '%s'"
911
- (string_of_name namei.node)
912
- | Some (_ , tag_ctor_id ) when referent_is_item cx tag_ctor_id ->
913
- (*
914
- * FIXME we should actually check here that the function
915
- * is a tag value-ctor. For now this actually allows any
916
- * function returning a tag type to pass as a tag pattern.
917
- *)
918
- resolve_pat_tag namei pats tag_ctor_id
919
- | _ -> not_tag_ctor namei
920
- end
910
+ Ast. PAT_tag (lval , pats ) ->
911
+ let lval_nm = lval_to_name lval in
912
+ let lval_id = lval_base_id lval in
913
+ let tag_ctor_id = lval_to_referent cx lval_id in
914
+ if referent_is_item cx tag_ctor_id
915
+ (*
916
+ * FIXME we should actually check here that the function
917
+ * is a tag value-ctor. For now this actually allows any
918
+ * function returning a tag type to pass as a tag pattern.
919
+ *)
920
+ then resolve_pat_tag lval_nm lval_id pats tag_ctor_id
921
+ else not_tag_ctor lval_nm lval_id
921
922
| _ -> ()
922
923
in
923
924
@@ -968,8 +969,8 @@ let process_crate
968
969
let passes_2 =
969
970
[|
970
971
(scope_stack_managing_visitor scopes
971
- (pattern_resolving_visitor cx scopes
972
- Walk. empty_visitor))
972
+ (pattern_resolving_visitor cx
973
+ Walk. empty_visitor))
973
974
|]
974
975
in
975
976
log cx " running primary resolve passes" ;
0 commit comments