Browse Source

[display] check type of ENew before following it away

closes #7906
Simon Krajewski 6 năm trước cách đây
mục cha
commit
070b6897eb
2 tập tin đã thay đổi với 28 bổ sung3 xóa
  1. 4 3
      src/typing/typer.ml
  2. 24 0
      tests/display/src/cases/Issue7906.hx

+ 4 - 3
src/typing/typer.ml

@@ -1722,13 +1722,13 @@ and type_new ctx path el with_type force_inline p =
 			error "Constructor is not a function" p
 	in
 	let t = if (fst path).tparams <> [] then
-		follow (Typeload.load_instance ctx path false)
+		Typeload.load_instance ctx path false
 	else try
 		ctx.call_argument_stack <- el :: ctx.call_argument_stack;
-		let t = follow (Typeload.load_instance ctx path true) in
+		let t = Typeload.load_instance ctx path true in
 		ctx.call_argument_stack <- List.tl ctx.call_argument_stack;
 		(* Try to properly build @:generic classes here (issue #2016) *)
-		begin match t with
+		begin match follow t with
 			| TInst({cl_kind = KGeneric } as c,tl) -> follow (Generic.build_generic ctx c p tl)
 			| _ -> t
 		end
@@ -1760,6 +1760,7 @@ and type_new ctx path el with_type force_inline p =
 			error ((s_type_path (t_infos mt).mt_path) ^ " cannot be constructed") p
 	in
 	DisplayEmitter.check_display_type ctx t (pos path);
+	let t = follow t in
 	let build_constructor_call c tl =
 		let ct, f = get_constructor ctx c tl p in
 		check_constructor_access ctx c f p;

+ 24 - 0
tests/display/src/cases/Issue7906.hx

@@ -0,0 +1,24 @@
+package cases;
+
+class Issue7906 extends DisplayTestCase {
+	/**
+		class Main {
+			static function main() {
+				var method:Ha{-1-}xeRequestMethod;
+				n{-2-}ew Ha{-3-}xeRequestMethod();
+			}
+		}
+
+		typedef {-4-}HaxeRequestMethod{-5-} = RequestMethod;
+
+		abstract RequestMethod(String) to String {
+			public function {-6-}new{-7-}()
+				this = "";
+		}
+	**/
+	function test() {
+		eq(range(4, 5), position(pos(1)));
+		eq(range(6, 7), position(pos(2)));
+		eq(range(4, 5), position(pos(3)));
+	}
+}