瀏覽代碼

don't allow `macro new` on abstracts
fixes #8551

Aleksandr Kuzmenko 6 年之前
父節點
當前提交
d09836d90a

+ 4 - 0
src/typing/typeloadFields.ml

@@ -217,6 +217,10 @@ let transform_abstract_field com this_t a_t a f =
 			if fu.f_expr <> None then error "MultiType constructors cannot have a body" f.cff_pos;
 			f.cff_access <- (AExtern,null_pos) :: f.cff_access;
 		end;
+		(try
+			let _, p = List.find (fun (acc, _) -> acc = AMacro) f.cff_access in
+			error "Macro abstract constructors are not supported" p
+		with Not_found -> ());
 		(* We don't want the generated expression positions to shadow the real code. *)
 		let p = { p with pmax = p.pmin } in
 		let fu = {

+ 9 - 0
tests/misc/projects/Issue8551/Main.hx

@@ -0,0 +1,9 @@
+class Main {
+	static function main() {}
+}
+
+abstract Dummy(Int) {
+	macro public function new(v:Int) {
+		this = v;
+	}
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:6: characters 2-7 : Macro abstract constructors are not supported