Sfoglia il codice sorgente

Fix arrow function syntax printing edge-case (#9386)

* Fix arrow syntax printing where a function returns a function

* Add regression test for fun->fun printing issue (#9385)

* Trying to fix unexpected test failure
George Corney 5 anni fa
parent
commit
addce2b341
2 ha cambiato i file con 11 aggiunte e 1 eliminazioni
  1. 5 1
      std/haxe/macro/Printer.hx
  2. 6 0
      tests/unit/src/unit/TestMacro.hx

+ 5 - 1
std/haxe/macro/Printer.hx

@@ -128,7 +128,11 @@ class Printer {
 					default: true;
 				}
 				var argStr = args.map(printComplexType).join(", ");
-				(wrapArgumentsInParentheses ? '($argStr)' : argStr) + " -> " + printComplexType(ret);
+				(wrapArgumentsInParentheses ? '($argStr)' : argStr) + " -> " + (switch ret {
+					// wrap return type in parentheses if it's also a function
+					case TFunction(_): '(${printComplexType(ret)})';
+					default: printComplexType(ret);
+				});
 			case TAnonymous(fields): "{ " + [for (f in fields) printField(f) + "; "].join("") + "}";
 			case TParent(ct): "(" + printComplexType(ct) + ")";
 			case TOptional(ct): "?" + printComplexType(ct);

+ 6 - 0
tests/unit/src/unit/TestMacro.hx

@@ -84,6 +84,12 @@ class TestMacro extends Test {
 			p.printComplexType( TFunction( [ TOptional( TNamed('a', macro :Int) ) ], macro :Int) ),
 			"(?a:Int) -> Int"
 		);
+		//	function returning function
+		eq(
+			// see issue #9385
+			p.printComplexType( TFunction( [], TFunction([], macro :Int)) ),
+			"() -> (() -> Int)"
+		);
 		eq(p.printComplexType(macro :(a:X) -> Y), "(a:X) -> Y");
 		eq(p.printComplexType(macro :(?a:X) -> Y), "(?a:X) -> Y");
 		eq(p.printComplexType(macro :((?a:X)) -> Y), "((?a:X)) -> Y");