Browse Source

Closes #9014 (#9241)

* Closes #9014

* Dodge all reviews
RblSb 5 năm trước cách đây
mục cha
commit
385de91f19

+ 4 - 1
src/typing/typeloadFields.ml

@@ -1100,7 +1100,10 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	end;
 	let parent = (if not fctx.is_static then get_parent c (fst f.cff_name) else None) in
 	let dynamic = List.mem_assoc ADynamic f.cff_access || (match parent with Some { cf_kind = Method MethDynamic } -> true | _ -> false) in
-	if fctx.is_inline && dynamic then error (fst f.cff_name ^ ": You can't have both 'inline' and 'dynamic'") p;
+	if fctx.is_inline && dynamic then error (fst f.cff_name ^ ": 'inline' is not allowed on 'dynamic' functions") p;
+	let is_override = Option.is_some fctx.override in
+	if (is_override && fctx.is_static) then error (fst f.cff_name ^ ": 'override' is not allowed on 'static' functions") p;
+
 	ctx.type_params <- if fctx.is_static && not fctx.is_abstract_member then params else params @ ctx.type_params;
 	(* TODO is_lib: avoid forcing the return type to be typed *)
 	let ret = if fctx.field_kind = FKConstructor then ctx.t.tvoid else type_opt (ctx,cctx) p fd.f_type in

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

@@ -0,0 +1,7 @@
+class Main extends Base {
+	static function main() {}
+	override static function foo():Void {}
+	dynamic inline function bar():Void {}
+}
+
+class Base {}

+ 2 - 0
tests/misc/projects/Issue9014/compile-fail.hxml

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

+ 2 - 0
tests/misc/projects/Issue9014/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:3: characters 2-40 : foo: 'override' is not allowed on 'static' functions
+Main.hx:4: characters 2-39 : bar: 'inline' is not allowed on 'dynamic' functions