فهرست منبع

don't mk_mono when creating mono field access

closes #11881
Simon Krajewski 8 ماه پیش
والد
کامیت
ffe8df0195

+ 28 - 0
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 ->

+ 1 - 1
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

+ 3 - 4
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
 

+ 6 - 0
tests/misc/projects/Issue11881/Main.hx

@@ -0,0 +1,6 @@
+function main() {
+	var logs = [];
+	for (l in logs) {
+		logs.push(l.msg);
+	}
+}

+ 2 - 0
tests/misc/projects/Issue11881/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 2 - 0
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> } }

+ 2 - 2
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> } }
+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> } }