Browse Source

forbid abstract constructors (closes #10426)

Aleksandr Kuzmenko 3 years ago
parent
commit
01ae5844a1

+ 5 - 1
src/typing/typeloadFields.ml

@@ -1249,7 +1249,11 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	} in
 	} in
 	if fctx.is_final then add_class_field_flag cf CfFinal;
 	if fctx.is_final then add_class_field_flag cf CfFinal;
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
 	if fctx.is_extern then add_class_field_flag cf CfExtern;
-	if fctx.is_abstract then add_class_field_flag cf CfAbstract;
+	if fctx.is_abstract then begin
+		if fctx.field_kind = FKConstructor then
+			display_error ctx "Constructors cannot be abstract" p;
+		add_class_field_flag cf CfAbstract;
+	end;
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
 	if fctx.is_abstract_member then add_class_field_flag cf CfImpl;
 	if fctx.is_generic then add_class_field_flag cf CfGeneric;
 	if fctx.is_generic then add_class_field_flag cf CfGeneric;
 	begin match fctx.overload with
 	begin match fctx.overload with

+ 7 - 0
tests/misc/projects/Issue10426/Main.hx

@@ -0,0 +1,7 @@
+class Main extends Abstr {
+	static function main() {}
+}
+
+abstract class Abstr {
+	abstract function new():Void;
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:6: characters 2-31 : Constructors cannot be abstract