Browse Source

[typer] delay @:using resolution

closes #10107
Simon Krajewski 2 years ago
parent
commit
ea3203db4d

+ 9 - 4
src/typing/typeloadFields.ml

@@ -507,7 +507,10 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 							| TClassDecl { cl_kind = KAbstractImpl a } -> t_infos (TAbstractDecl a)
 							| _ -> t_infos mt
 					in
-					ti.mt_using <- (filter_classes types) @ ti.mt_using;
+					(* Delay for #10107, but use delay_late to make sure base classes run before their children do. *)
+					delay_late ctx PConnectField (fun () ->
+						ti.mt_using <- (filter_classes types) @ ti.mt_using
+					)
 				with Exit ->
 					typing_error "dot path expected" (pos e)
 			) el;
@@ -517,7 +520,6 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 	in
 	(* let errors go through to prevent resume if build fails *)
 	let f_build = List.fold_left loop [] meta in
-	(* Go for @:using in parents and interfaces *)
 	let f_enum = match mt with
 		| TClassDecl ({cl_kind = KAbstractImpl a} as c) when a.a_enum ->
 			Some (fun () ->
@@ -528,12 +530,15 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 				fbuild e;
 			)
 		| TClassDecl { cl_super = csup; cl_implements = interfaces; cl_kind = kind } ->
+			(* Go for @:using in parents and interfaces *)
 			let ti = t_infos mt in
 			let inherit_using (c,_) =
 				ti.mt_using <- ti.mt_using @ (t_infos (TClassDecl c)).mt_using
 			in
-			Option.may inherit_using csup;
-			List.iter inherit_using interfaces;
+			delay_late ctx PConnectField (fun () ->
+				Option.may inherit_using csup;
+				List.iter inherit_using interfaces;
+			);
 			None
 		| _ ->
 			None

+ 7 - 0
tests/misc/projects/Issue10107/Main.hx

@@ -0,0 +1,7 @@
+@:using(Main)
+typedef B = {
+	> A,
+};
+
+typedef A = {};
+function main() {}

+ 3 - 0
tests/misc/projects/Issue10107/compile.hxml

@@ -0,0 +1,3 @@
+-cp src
+-main Main
+--interp