Skip to content

Commit

Permalink
don't mk_mono when creating mono field access
Browse files Browse the repository at this point in the history
closes #11881
  • Loading branch information
Simn committed Dec 17, 2024
1 parent 400c79d commit ffe8df0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
28 changes: 28 additions & 0 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ and s_mono ctx m =
end
| Some t -> s_type ctx t

(* TODO: refactor these two functions... *)
and s_mono_explicit ctx m =
let print_name id extra =
let s = if show_mono_ids then
Printf.sprintf "Unknown<%d>" id
else
"Unknown"
in
let s = s ^ extra in
s_mono_modifiers s m
in
begin try
let id = List.assq m (!ctx) in
print_name id ""
with Not_found ->
let id = List.length !ctx in
ctx := (m,id) :: !ctx;
match m.tm_type with
| None ->
let s_const =
let s = s_mono_constraint_kind (s_type ctx) (!monomorph_classify_constraints_ref m) in
if s = "" then s else " : " ^ s
in
print_name id s_const
| Some t ->
print_name id (" := " ^ (s_type ctx) t)
end

and s_type ctx t =
match t with
| TMono r ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/fields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
end;
| TMono r ->
let mk_field () = {
(mk_field i (mk_mono()) p null_pos) with
(mk_field i (spawn_monomorph ctx p) p null_pos) with
cf_kind = Var { v_read = AccNormal; v_write = if is_set then AccNormal else AccNo }
} in
let rec check_constr = function
Expand Down
7 changes: 3 additions & 4 deletions src/typing/typeloadFunction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ let type_function ctx (args : function_arguments) ret e do_display p =
| _ -> e
in
List.iter (fun r -> r := Closed) ctx.e.opened;
let close () = List.iter (fun (m,p) -> safe_mono_close ctx m p) ctx.e.monomorphs.perfunction; in
let mono_debug = Meta.has (Meta.Custom ":debug.mono") ctx.f.curfield.cf_meta in
if mono_debug then begin
let pctx = print_context () in
let print_mono i m =
Printf.sprintf "%4i: %s" i (s_mono pctx m)
Printf.sprintf "%4i: %s" i (s_mono_explicit pctx m)
in
print_endline "BEFORE:";
let monos = List.mapi (fun i (m,p) ->
Expand All @@ -174,9 +173,9 @@ let type_function ctx (args : function_arguments) ret e do_display p =
Printf.sprintf "%i:%i" l1 p1
end in
print_endline (Printf.sprintf "%s (%s)" s spos);
safe_mono_close ctx m p;
(i,m,p,s)
) ctx.e.monomorphs.perfunction in
close();
print_endline "CHANGED:";
List.iter (fun (i,m,p,s) ->
let s' = print_mono i m in
Expand All @@ -185,7 +184,7 @@ let type_function ctx (args : function_arguments) ret e do_display p =
end
) monos
end else
close();
List.iter (fun (m,p) -> safe_mono_close ctx m p) ctx.e.monomorphs.perfunction;
if is_position_debug then print_endline ("typing:\n" ^ (Texpr.dump_with_pos "" e));
e

Expand Down
6 changes: 6 additions & 0 deletions tests/misc/projects/Issue11881/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function main() {
var logs = [];
for (l in logs) {
logs.push(l.msg);
}
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11881/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--main Main
--interp
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11881/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Main.hx:4: characters 13-18 : Recursive type
Main.hx:4: characters 13-18 : ... Unknown<0> appears in { msg: Unknown<0> : { msg : Unknown<0> } }
4 changes: 2 additions & 2 deletions tests/misc/projects/Issue7997/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Main.hx:4: characters 4-19 : Recursive type
Main.hx:4: characters 4-19 : ... Unknown<0> appears in { args: Unknown<0> : { field : Unknown<1>, args : Unknown<0> } }
Main.hx:4: characters 4-13 : Recursive type
Main.hx:4: characters 4-13 : ... Unknown<0> appears in { args: Unknown<0> : { field : Unknown<1>, args : Unknown<0> } }

0 comments on commit ffe8df0

Please sign in to comment.