Przeglądaj źródła

[typer] allow @:structInit on abstract classes

closes #10685
Simon Krajewski 3 lat temu
rodzic
commit
58b90d09a0

+ 0 - 2
src/typing/typeloadFields.ml

@@ -1838,8 +1838,6 @@ let init_class ctx c p context_init herits fields =
 	if has_struct_init then
 		if (has_class_flag c CInterface) then
 			display_error ctx.com "@:structInit is not allowed on interfaces" struct_init_pos
-		else if (has_class_flag c CAbstract) then
-			display_error ctx.com "@:structInit is not allowed on abstract classes" struct_init_pos
 		else
 			ensure_struct_init_constructor ctx c fields p;
 	begin match cctx.uninitialized_final with

+ 19 - 0
tests/unit/src/unit/issues/Issue10685.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+@:structInit
+private abstract class A {
+	public final x:Int;
+}
+
+@:structInit
+private class B extends A {
+	public var y:Int;
+}
+
+class Issue10685 extends Test {
+	function test() {
+		var b:B = {x: 1, y: 2};
+		eq(1, b.x);
+		eq(2, b.y);
+	}
+}