2
0
Эх сурвалжийг харах

[typer] process extern arguments properly

closes #7752
Simon Krajewski 6 жил өмнө
parent
commit
308d19ceb1

+ 12 - 1
src/typing/typeloadFields.ml

@@ -1087,8 +1087,19 @@ let create_method (ctx,cctx,fctx) c f fd p =
 		end;
 		end;
 		t
 		t
 	) "type_fun" in
 	) "type_fun" in
-	if fctx.do_bind then bind_type (ctx,cctx,fctx) cf r (match fd.f_expr with Some e -> snd e | None -> f.cff_pos)
+	if fctx.do_bind then
+		bind_type (ctx,cctx,fctx) cf r (match fd.f_expr with Some e -> snd e | None -> f.cff_pos)
 	else begin
 	else begin
+		delay ctx PTypeField (fun () ->
+			(* We never enter type_function so we're missing out on the argument processing there. Let's do it here. *)
+			List.iter2 (fun (n,c,t) ((_,pn),_,m,_,_) ->
+				ignore(TypeloadFunction.process_function_arg ctx n t c fctx.is_display_field pn);
+				if DisplayPosition.encloses_display_position pn then begin
+					let v = add_local_with_origin ctx TVOArgument n t pn in
+					DisplayEmitter.display_variable ctx v pn;
+				end
+			) args fd.f_args;
+		);
 		check_field_display ctx fctx c cf;
 		check_field_display ctx fctx c cf;
 		if fd.f_expr <> None && not (fctx.is_inline || fctx.is_macro) then ctx.com.warning "Extern non-inline function may not have an expression" p;
 		if fd.f_expr <> None && not (fctx.is_inline || fctx.is_macro) then ctx.com.warning "Extern non-inline function may not have an expression" p;
 	end;
 	end;

+ 6 - 3
src/typing/typeloadFunction.ml

@@ -85,11 +85,14 @@ let type_function_arg_value ctx t c do_display =
 			in
 			in
 			loop e
 			loop e
 
 
+let process_function_arg ctx n t c do_display p =
+	if starts_with n '$' then error "Function argument names starting with a dollar are not allowed" p;
+	type_function_arg_value ctx t c do_display
+
 let type_function ctx args ret fmode f do_display p =
 let type_function ctx args ret fmode f do_display p =
 	let fargs = List.map2 (fun (n,c,t) ((_,pn),_,m,_,_) ->
 	let fargs = List.map2 (fun (n,c,t) ((_,pn),_,m,_,_) ->
-		if starts_with n '$' then error "Function argument names starting with a dollar are not allowed" p;
-		let c = type_function_arg_value ctx t c do_display in
-		let v,c = add_local_with_origin ctx TVOArgument n t pn , c in
+		let c = process_function_arg ctx n t c do_display pn in
+		let v = add_local_with_origin ctx TVOArgument n t pn in
 		v.v_meta <- v.v_meta @ m;
 		v.v_meta <- v.v_meta @ m;
 		if do_display && DisplayPosition.encloses_display_position pn then
 		if do_display && DisplayPosition.encloses_display_position pn then
 			DisplayEmitter.display_variable ctx v pn;
 			DisplayEmitter.display_variable ctx v pn;

+ 21 - 0
tests/display/src/cases/Issue7752.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue7752 extends DisplayTestCase {
+	/**
+class Foo {
+	extern function foo(te{-1-}st:Int):Void;
+}
+	**/
+	function test() {
+		eq("Int", type(pos(1)));
+	}
+
+	/**
+class Foo {
+	extern function foo(test:Int = 1{-1-}2):Void;
+}
+	**/
+	function test2() {
+		eq("Int", type(pos(1)));
+	}
+}

+ 9 - 0
tests/misc/projects/Issue7752/Main.hx

@@ -0,0 +1,9 @@
+class Foo {
+	extern function foo(test:Int = "foo"):Void;
+}
+
+class Main {
+	static public function main() {
+
+	}
+}

+ 9 - 0
tests/misc/projects/Issue7752/Main2.hx

@@ -0,0 +1,9 @@
+class Foo {
+	extern function foo($test:Int):Void;
+}
+
+class Main2 {
+	static public function main() {
+
+	}
+}

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

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

+ 1 - 0
tests/misc/projects/Issue7752/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:2: characters 33-38 : String should be Int

+ 2 - 0
tests/misc/projects/Issue7752/compile2-fail.hxml

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

+ 1 - 0
tests/misc/projects/Issue7752/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+Main2.hx:2: characters 22-27 : Function argument names starting with a dollar are not allowed