瀏覽代碼

[typer] don't allow @:structInit to call abstract constructors

closes #11342
Simon Krajewski 1 年之前
父節點
當前提交
5c05e6de76

+ 1 - 0
src/typing/typer.ml

@@ -884,6 +884,7 @@ and type_object_decl ctx fl with_type p =
 		let t, fl = type_fields a.a_fields in
 		mk (TObjectDecl fl) t p
 	| ODKWithClass (c,tl) ->
+		no_abstract_constructor c p;
 		let fa = FieldAccess.get_constructor_access c tl p in
 		let ctor = fa.fa_field in
 		let args = match follow (FieldAccess.get_map_function fa ctor.cf_type) with

+ 8 - 0
tests/misc/projects/Issue11342/Main.hx

@@ -0,0 +1,8 @@
+@:structInit
+abstract class Foo {
+	public function new(a:Int, b:Int) {}
+}
+
+function main() {
+	var x:Foo = {a: 1, b: 2};
+}

+ 1 - 0
tests/misc/projects/Issue11342/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

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

@@ -0,0 +1 @@
+Main.hx:7: characters 14-26 : Foo is abstract and cannot be constructed