Ver Fonte

[printer] don't print `var` with `final` accessor. Closes #8859 (#8863)

* [printer] don't print `var` with `final` accessor. Closes #8859

* [test] add regression test for #8859
George Corney há 5 anos atrás
pai
commit
29a1dc8596
2 ficheiros alterados com 17 adições e 1 exclusões
  1. 1 1
      std/haxe/macro/Printer.hx
  2. 16 0
      tests/unit/src/unit/issues/Issue8859.hx

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

@@ -165,7 +165,7 @@ class Printer {
 			+ (field.meta != null && field.meta.length > 0 ? field.meta.map(printMetadata).join('\n$tabs') + '\n$tabs' : "")
 			+ (field.access != null && field.access.length > 0 ? field.access.map(printAccess).join(" ") + " " : "")
 			+ switch (field.kind) {
-				case FVar(t, eo): 'var ${field.name}' + opt(t, printComplexType, " : ") + opt(eo, printExpr, " = ");
+				case FVar(t, eo): ((field.access != null && field.access.has(AFinal)) ? '' : 'var ') + '${field.name}' + opt(t, printComplexType, " : ") + opt(eo, printExpr, " = ");
 				case FProp(get, set, t, eo): 'var ${field.name}($get, $set)' + opt(t, printComplexType, " : ") + opt(eo, printExpr, " = ");
 				case FFun(func): 'function ${field.name}' + printFunction(func);
 			}

+ 16 - 0
tests/unit/src/unit/issues/Issue8859.hx

@@ -0,0 +1,16 @@
+package unit.issues;
+
+class Issue8859 extends Test {
+	function test() {
+		var td = macro class X {
+			final x: Int = 0;
+			var y: Int = 0;
+			private final z: Int = 0;
+			private var w: Int = 0;
+		}
+		var printer = new haxe.macro.Printer();
+		var s = printer.printTypeDefinition(td);
+		s = ~/[\t\n\r]/g.replace(s, "");
+		eq("class X {final x : Int = 0;var y : Int = 0;private final z : Int = 0;private var w : Int = 0;}", s);
+	}
+}