Просмотр исходного кода

support awkward overload inline behavior (see #3846)

Simon Krajewski 10 лет назад
Родитель
Сommit
5f24cff0d1
2 измененных файлов с 45 добавлено и 3 удалено
  1. 28 0
      tests/unit/src/unit/issues/Issue3846.hx
  2. 17 3
      typer.ml

+ 28 - 0
tests/unit/src/unit/issues/Issue3846.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+// they don't allow this insanity
+#if (!java && !cs)
+
+private class Extern {
+
+	@:keep
+	static function mytest(a:Dynamic) {
+		return a;
+	}
+
+    @:overload( function (a:Int):Dynamic {})
+    inline public static function test(a:String):Dynamic {
+        return mytest(a);
+    }
+}
+
+#end
+
+class Issue3846 extends Test {
+	function test() {
+		#if (!java && !cs)
+        eq("coucou", Extern.test("coucou"));
+        eq(1, Extern.test(1));
+		#end
+	}
+}

+ 17 - 3
typer.ml

@@ -749,9 +749,23 @@ let unify_call_args ctx el args r p inline force_inline =
 	List.map fst el,tf
 
 let unify_field_call ctx fa el args ret p inline =
-	let map_cf map cf = map (monomorphs cf.cf_params cf.cf_type),cf in
+	let map_cf cf0 map cf =
+		let t = map (monomorphs cf.cf_params cf.cf_type) in
+		begin match cf.cf_expr,cf.cf_kind with
+		| None,Method MethInline when not ctx.com.config.pf_overload ->
+			(* This is really awkward and shouldn't be here. We'll keep it for
+			   3.2 in order to not break code that relied on the quirky behavior
+			   in 3.1.3, but it should really be reviewed afterwards.
+			   Related issue: https://github.com/HaxeFoundation/haxe/issues/3846
+			*)
+			cf.cf_expr <- cf0.cf_expr;
+		| _ ->
+			()
+		end;
+		t,cf
+	in
 	let expand_overloads map cf =
-		(TFun(args,ret),cf) :: (List.map (map_cf map) cf.cf_overloads)
+		(TFun(args,ret),cf) :: (List.map (map_cf cf map) cf.cf_overloads)
 	in
 	let candidates,co,cf,mk_fa = match fa with
 		| FStatic(c,cf) ->
@@ -761,7 +775,7 @@ let unify_field_call ctx fa el args ret p inline =
 		| FInstance(c,tl,cf) ->
 			let map = apply_params c.cl_params tl in
 			let cfl = if cf.cf_name = "new" || not (Meta.has Meta.Overload cf.cf_meta && ctx.com.config.pf_overload) then
-				List.map (map_cf map) cf.cf_overloads
+				List.map (map_cf cf map) cf.cf_overloads
 			else
 				List.map (fun (t,cf) -> map (monomorphs cf.cf_params t),cf) (Typeload.get_overloads c cf.cf_name)
 			in