Browse Source

Revert "[typer] unify function argument typing"

This reverts commit c22400b0ed54700f31a755bbac524c13c1bed637.
Simon Krajewski 7 years ago
parent
commit
e3e62571f7

+ 0 - 1
extra/CHANGES.txt

@@ -2,7 +2,6 @@ XXXX-XX-XX:
 
 	General improvements and optimizations:
 
-	all : cleaned up function argument type handling when `?` is used (#6972)
 	php : Optimized haxe.ds.Vector (VectorData is not Array anymore)
 	php : Optimized `Map.copy()` and `Array.copy()`
 	php : Support native PHP generators. See `php.Syntax.yield()` and `php.Generator`

+ 7 - 12
src/typing/typeloadFunction.ml

@@ -28,18 +28,13 @@ open DisplayException
 open Common
 open Error
 
-let type_function_arg ctx t eo opt p =
-	if not opt then begin match eo with
-		| Some (EConst(Ident "null"),_) -> ctx.t.tnull t,eo
-		| _ -> t,eo
-	end else begin
-		let t,eo = match eo with
-		| Some (EConst(Ident "null"),_) -> ctx.t.tnull t,eo
-		| Some _ -> t,eo
-		| None -> ctx.t.tnull t,Some (EConst(Ident "null"),null_pos)
-		in
-		t, eo
-	end
+let type_function_arg ctx t e opt p =
+	if opt then
+		let e = (match e with None -> Some (EConst (Ident "null"),null_pos) | _ -> e) in
+		ctx.t.tnull t, e
+	else
+		let t = match e with Some (EConst (Ident "null"),null_pos) -> ctx.t.tnull t | _ -> t in
+		t, e
 
 let save_field_state ctx =
 	let old_ret = ctx.ret in

+ 1 - 3
tests/unit/src/unit/HelperMacros.hx

@@ -26,9 +26,7 @@ class HelperMacros {
 		function isNullable(t:haxe.macro.Type) {
 			return switch (t) {
 				case TMono(null): false;
-				case TMono(t):
-					var t = t.get();
-					t == null ? false : isNullable(t);
+				case TMono(t): isNullable(t.get());
 				case TAbstract(_.get() => {pack: [], name: "Null"}, _): true;
 				case TLazy(f): isNullable(f());
 				case TType(_.get() => td, tl): isNullable(applyTypeParameters(td.type, td.params, tl));

+ 2 - 2
tests/unit/src/unit/TestMisc.hx

@@ -377,7 +377,7 @@ class TestMisc extends Test {
 		eq( opt2().x, 5 );
 		eq( opt2().y, "hello" );
 
-		#if !(flash || cpp || cs || java || hl)
+		#if !(flash || cpp || cs || java)
 		eq( opt2(null, null).x, 5 );
 		#end
 		eq( opt2(0, null).y, "hello" );
@@ -415,7 +415,7 @@ class TestMisc extends Test {
 		// var opt4c : ?Null<Int> -> Null<Int> = opt4;
 		// var opt4c : ?Int -> Int = opt4;
 
-		var opt5 = function(a:Int, ?b:Null<Int> = 2) return a + b;
+		var opt5 = function(a:Int, ?b = 2) return a + b;
 		eq(3, opt5(1));
 		eq(3, opt5(1, 2));
 		eq(3, opt5(1, null));

+ 1 - 1
tests/unit/src/unit/TestType.hx

@@ -249,7 +249,7 @@ class TestType extends Test {
 		func = function(a,b,c):Int return throw "error";
 		eq(5, cb(b, 0));
 
-		var optfunc = function(a:Int, b:Int, ?c:Null<Int> = 2) return a + b + c;
+		var optfunc = function(a:Int, b:Int, ?c:Int = 2) return a + b + c;
 		eq(6, optfunc.bind(1)(3));
 		eq(6, optfunc.bind(1, 3)());
 

+ 2 - 6
tests/unit/src/unit/issues/Issue6972.hx

@@ -4,7 +4,6 @@ import unit.HelperMacros.isNullable as n;
 
 class Issue6972 extends unit.Test {
 	function test() {
-		f0(1);
 		f1(1);
 		f2(1);
 		f3();
@@ -14,7 +13,6 @@ class Issue6972 extends unit.Test {
 		f7();
 		f8();
 
-		f10();
 		f11();
 		f12();
 		f13();
@@ -25,7 +23,6 @@ class Issue6972 extends unit.Test {
 		f18();
 	}
 
-	function f0(x) f(n(x));
 	function f1(x:Int) f(n(x));
 	function f2(x:Null<Int>) t(n(x));
 	function f3(x = null) t(n(x));
@@ -35,13 +32,12 @@ class Issue6972 extends unit.Test {
 	function f7(x:Null<Int> = 1) t(n(x));
 	function f8(x:Null<Int> = null) t(n(x));
 
-	function f10(?x) t(n(x));
 	function f11(?x:Int) t(n(x));
 	function f12(?x:Null<Int>) t(n(x));
 	function f13(?x = null) t(n(x));
-	function f14(?x = 1) f(n(x));
+	function f14(?x = 1) t(n(x));
 	function f15(?x:Int = null) t(n(x));
-	function f16(?x:Int = 1) f(n(x));
+	function f16(?x:Int = 1) t(n(x));
 	function f17(?x:Null<Int> = 1) t(n(x));
 	function f18(?x:Null<Int> = null) t(n(x));
 }