diff --git a/src/core/tPrinting.ml b/src/core/tPrinting.ml index 4b1567c4142..b4bcd70adcf 100644 --- a/src/core/tPrinting.ml +++ b/src/core/tPrinting.ml @@ -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 -> diff --git a/src/typing/fields.ml b/src/typing/fields.ml index f58f452b22b..8bfad9d0326 100644 --- a/src/typing/fields.ml +++ b/src/typing/fields.ml @@ -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 diff --git a/src/typing/typeloadFunction.ml b/src/typing/typeloadFunction.ml index 17e54a04386..28b83e0a316 100644 --- a/src/typing/typeloadFunction.ml +++ b/src/typing/typeloadFunction.ml @@ -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) -> @@ -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 @@ -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 diff --git a/tests/misc/projects/Issue11881/Main.hx b/tests/misc/projects/Issue11881/Main.hx new file mode 100644 index 00000000000..d327d34228c --- /dev/null +++ b/tests/misc/projects/Issue11881/Main.hx @@ -0,0 +1,6 @@ +function main() { + var logs = []; + for (l in logs) { + logs.push(l.msg); + } +} diff --git a/tests/misc/projects/Issue11881/compile-fail.hxml b/tests/misc/projects/Issue11881/compile-fail.hxml new file mode 100644 index 00000000000..b30a755894b --- /dev/null +++ b/tests/misc/projects/Issue11881/compile-fail.hxml @@ -0,0 +1,2 @@ +--main Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11881/compile-fail.hxml.stderr b/tests/misc/projects/Issue11881/compile-fail.hxml.stderr new file mode 100644 index 00000000000..c599b0b692a --- /dev/null +++ b/tests/misc/projects/Issue11881/compile-fail.hxml.stderr @@ -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> } } \ No newline at end of file diff --git a/tests/misc/projects/Issue7997/compile-fail.hxml.stderr b/tests/misc/projects/Issue7997/compile-fail.hxml.stderr index ed97e9c40ee..d5ba5df89cb 100644 --- a/tests/misc/projects/Issue7997/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue7997/compile-fail.hxml.stderr @@ -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> } } \ No newline at end of file +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> } } \ No newline at end of file