Browse Source

[typer] use new function-style syntax when printing

closes #7001
Simon Krajewski 7 years ago
parent
commit
b940c805aa

+ 10 - 3
src/core/type.ml

@@ -995,9 +995,16 @@ let rec s_type ctx t =
 	| TFun ([],t) ->
 		"Void -> " ^ s_fun ctx t false
 	| TFun (l,t) ->
-		String.concat " -> " (List.map (fun (s,b,t) ->
-			(if b then "?" else "") ^ (if s = "" then "" else s ^ " : ") ^ s_fun ctx t true
-		) l) ^ " -> " ^ s_fun ctx t false
+		let args = match l with
+			| [] -> "()"
+			| ["",b,t] -> Printf.sprintf "%s%s" (if b then "?" else "") (s_fun ctx t true)
+			| _ ->
+				let args = String.concat ", " (List.map (fun (s,b,t) ->
+					(if b then "?" else "") ^ (if s = "" then "" else s ^ " : ") ^ s_fun ctx t true
+				) l) in
+				"(" ^ args ^ ")"
+		in
+		Printf.sprintf "%s -> %s" args (s_fun ctx t false)
 	| TAnon a ->
 		begin
 			match !(a.a_status) with

+ 1 - 1
tests/display/src/cases/Basic.hx

@@ -111,6 +111,6 @@ class Basic extends DisplayTestCase {
 	}
 	**/
 	function testCtorClosureType() {
-		eq("someName : Int -> cases.Some", type(pos(1)));
+		eq("(someName : Int) -> cases.Some", type(pos(1)));
 	}
 }

+ 3 - 3
tests/display/src/cases/IImport.hx

@@ -14,9 +14,9 @@ class IImport extends DisplayTestCase {
 		eq(true, hasPath(fields(pos(7)), "ExprTools"));
 		eq(true, hasPath(fields(pos(4)), "ExprArrayTools"));
 		eq(true, hasPath(fields(pos(8)), "ExprArrayTools"));
-		eq(true, hasField(fields(pos(5)), "iter", "el : Array<haxe.macro.Expr> -> f : (haxe.macro.Expr -> Void) -> Void"));
-		eq(true, hasField(fields(pos(9)), "iter", "el : Array<haxe.macro.Expr> -> f : (haxe.macro.Expr -> Void) -> Void"));
-		eq("el : Array<haxe.macro.Expr> -> f : (haxe.macro.Expr -> Void) -> Void", type(pos(5)));
+		eq(true, hasField(fields(pos(5)), "iter", "(el : Array<haxe.macro.Expr>, f : (haxe.macro.Expr -> Void)) -> Void"));
+		eq(true, hasField(fields(pos(9)), "iter", "(el : Array<haxe.macro.Expr>, f : (haxe.macro.Expr -> Void)) -> Void"));
+		eq("(el : Array<haxe.macro.Expr>, f : (haxe.macro.Expr -> Void)) -> Void", type(pos(5)));
 		// TODO: test @position display. A bit annoying because it actually ends up in other files and we can't use markers.
 	}
 

+ 1 - 1
tests/display/src/cases/Issue6004.hx

@@ -11,6 +11,6 @@ class Issue6004 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq(true, hasField(fields(pos(1)), "bind", "(?a : Int -> Int) -> (?a : Int -> Int)", "method"));
+		eq(true, hasField(fields(pos(1)), "bind", "((?a : Int) -> Int) -> ((?a : Int) -> Int)", "method"));
 	}
 }

+ 4 - 4
tests/display/src/cases/Issue6265.hx

@@ -9,14 +9,14 @@ class Issue6265 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq("value : Dynamic -> Void", type(pos(1)));
-		eq("value : Dynamic -> Void", type(pos(2)));
+		eq("(value : Dynamic) -> Void", type(pos(1)));
+		eq("(value : Dynamic) -> Void", type(pos(2)));
 		eq("Void", type(pos(3)));
 		eq("String", type(pos(4)));
 		eq("String", type(pos(5)));
 		eq("String", type(pos(6)));
-		eq("x : Int -> Void", type(pos(7)));
-		eq("x : Int -> Void", type(pos(8)));
+		eq("(x : Int) -> Void", type(pos(7)));
+		eq("(x : Int) -> Void", type(pos(8)));
 		eq("Void", type(pos(9)));
 		eq("Int", type(pos(10)));
 		eq("Void", type(pos(11)));

+ 1 - 1
tests/display/src/cases/Issue6275.hx

@@ -13,7 +13,7 @@ class Issue6275 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq("s : String -> cases.Main", type(pos(2)));
+		eq("(s : String) -> cases.Main", type(pos(2)));
 		eq(range(4, 5), position(pos(1)));
 		eq(range(1, 3), usage(pos(2))[0]);
 	}

+ 1 - 1
tests/display/src/cases/Issue6740.hx

@@ -21,6 +21,6 @@ class Issue6740 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq(true, hasField(fields(pos(1)), "concat", "a : Array<String> -> Array<String>"));
+		eq(true, hasField(fields(pos(1)), "concat", "(a : Array<String>) -> Array<String>"));
 	}
 }

+ 1 - 1
tests/display/src/cases/Issue7171.hx

@@ -9,6 +9,6 @@ class Issue7171 extends DisplayTestCase {
 	}
 	**/
 	function test() {
-		eq("s : Dynamic -> String", type(pos(1)));
+		eq("(s : Dynamic) -> String", type(pos(1)));
 	}
 }

+ 1 - 1
tests/display/src/cases/PropertyAccessors.hx

@@ -15,6 +15,6 @@ class PropertyAccessors extends DisplayTestCase {
 		eq(range(3, 4), position(pos(1)));
 		eq(range(5, 6), position(pos(2)));
 		eq("Void -> String", type(pos(1)));
-		eq("s : String -> String", type(pos(2)));
+		eq("(s : String) -> String", type(pos(2)));
 	}
 }

+ 1 - 1
tests/display/src/cases/Toplevel.hx

@@ -357,6 +357,6 @@ class Toplevel extends DisplayTestCase {
 	**/
 	function testTypeParameterApplication() {
 		var toplevel = toplevel(pos(1));
-		eq(true, hasToplevel(toplevel, "member", "f1", "t : String -> Void"));
+		eq(true, hasToplevel(toplevel, "member", "f1", "(t : String) -> Void"));
 	}
 }

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

@@ -1,4 +1,4 @@
 Main2.hx:6: characters 2-46 : Field f has different type than in I
 Main2.hx:2: characters 2-44 : Interface field is defined here
-Main2.hx:6: characters 2-46 : s : String -> Void should be d : Dynamic -> Void
+Main2.hx:6: characters 2-46 : (s : String) -> Void should be (d : Dynamic) -> Void
 Main2.hx:6: characters 2-46 : String should be Dynamic

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

@@ -1,4 +1,4 @@
 Main.hx:5: lines 5-7 : Field test has different type than in I
 Main.hx:16: characters 2-32 : Interface field is defined here
-Main.hx:5: lines 5-7 : s : String -> Void should be s : Dynamic -> Void
+Main.hx:5: lines 5-7 : (s : String) -> Void should be (s : Dynamic) -> Void
 Main.hx:5: lines 5-7 : String should be Dynamic

+ 3 - 3
tests/misc/projects/Issue4540/compile-fail.hxml.stderr

@@ -1,4 +1,4 @@
-Main.hx:3: characters 36-55 : c : { test : String } -> Void should be Null<js.PromiseCallback<Int, Void>>
-Main.hx:3: characters 36-55 : c : { test : String } -> Void should be js.PromiseCallback<Int, Void>
-Main.hx:3: characters 36-55 : c : { test : String } -> Void should be haxe.extern.EitherType<Int -> Void, Int -> js.Promise<Void>>
+Main.hx:3: characters 36-55 : (c : { test : String }) -> Void should be Null<js.PromiseCallback<Int, Void>>
+Main.hx:3: characters 36-55 : (c : { test : String }) -> Void should be js.PromiseCallback<Int, Void>
+Main.hx:3: characters 36-55 : (c : { test : String }) -> Void should be haxe.extern.EitherType<Int -> Void, Int -> js.Promise<Void>>
 Main.hx:3: characters 36-55 : For function argument 'fulfillCallback'

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

@@ -1,7 +1,7 @@
 Main.hx:4: lines 4-7 : Could not find a suitable overload, reasons follow
 Main.hx:4: lines 4-7 : Overload resolution failed for Void -> js.jquery.JQuery
 Main.hx:4: lines 4-7 : Too many arguments
-Main.hx:4: lines 4-7 : Overload resolution failed for handler : (js.jquery.Event -> Void) -> js.jquery.JQuery
+Main.hx:4: lines 4-7 : Overload resolution failed for (handler : (js.jquery.Event -> Void)) -> js.jquery.JQuery
 Main.hx:6: characters 8-17 : Object requires field y
 Main.hx:6: characters 8-17 : For function argument 'handler'
 Main.hx:4: lines 4-7 : End of overload failure reasons

+ 1 - 1
tests/misc/projects/Issue5118/compile1.hxml.stderr

@@ -1,3 +1,3 @@
 <type p="$$normPath(::cwd::/Main.hx):8: characters 18-22">
-v : Int -&gt; haxe.ds.Option&lt;Int&gt;
+(v : Int) -&gt; haxe.ds.Option&lt;Int&gt;
 </type>

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

@@ -1,2 +1,2 @@
-Main.hx:12: characters 9-10 : x : Int -> E should be E
+Main.hx:12: characters 9-10 : (x : Int) -> E should be E
 Main.hx:10: characters 11-12 : Invalid match: Not enough patterns

+ 1 - 1
tests/unit/src/unit/issues/Issue3460.hx

@@ -8,6 +8,6 @@ private class MyClass {
 
 class Issue3460 extends Test {
 	function test() {
-		eq("x : Int -> String, x : String -> y : Bool -> Int", unit.issues.misc.Issue3460Macro.getOverloadString((null : MyClass)));
+		eq("(x : Int) -> String, (x : String, y : Bool) -> Int", unit.issues.misc.Issue3460Macro.getOverloadString((null : MyClass)));
 	}
 }

+ 6 - 6
tests/unit/src/unit/issues/Issue4799.hx

@@ -6,15 +6,15 @@ class Issue4799 extends Test {
 	function test() {
 		eq(typeString((null : Int)), "Int");
 		eq(typeString((null : (Int))), "Int");
-		eq(typeString((null : (Int,Int)->Int)), "Int -> Int -> Int");
-		eq(typeString((null : (a:Int,Int)->Int)), "a : Int -> Int -> Int");
-		eq(typeString((null : (a:Int, b:Int)->Int)), "a : Int -> b : Int -> Int");
+		eq(typeString((null : (Int,Int)->Int)), "(Int, Int) -> Int");
+		eq(typeString((null : (a:Int,Int)->Int)), "(a : Int, Int) -> Int");
+		eq(typeString((null : (a:Int, b:Int)->Int)), "(a : Int, b : Int) -> Int");
 		eq(typeString((null : (a:Int, Int, ?String->Void, ?b:(Int->Int)->Int, c:(a:Int)->Void)->Int)),
-		                      "a : Int -> Int -> (?String -> Void) -> ?b : ((Int -> Int) -> Int) -> c : (a : Int -> Void) -> Int");
+		                      "(a : Int, Int, (?String -> Void), ?b : ((Int -> Int) -> Int), c : ((a : Int) -> Void)) -> Int");
 		t(parseError("(Int,Int)->Int->Int"));
 		t(parseError("(a:Int)->Int->Int"));
-		eq(typeString((null : (Int,Int)->(Int->Int))), "Int -> Int -> (Int -> Int)");
-		eq(typeString((null : (a:Int)->(Int->Int))), "a : Int -> (Int -> Int)");
+		eq(typeString((null : (Int,Int)->(Int->Int))), "(Int, Int) -> (Int -> Int)");
+		eq(typeString((null : (a:Int)->(Int->Int))), "(a : Int) -> (Int -> Int)");
 	}
 
 	static macro function parseError(s:String) {