浏览代码

[typer] detect forced-inline on overridden field

closes #7824
Simon Krajewski 6 年之前
父节点
当前提交
9c8e8d1793

+ 1 - 0
src/core/type.ml

@@ -383,6 +383,7 @@ type flag_tclass_field =
 	| CfPublic
 	| CfExtern (* This is only set if the field itself is extern, not just the class. *)
 	| CfFinal
+	| CfOverridden
 
 (* Flags *)
 

+ 7 - 1
src/typing/calls.ml

@@ -28,7 +28,13 @@ let make_call ctx e params t ?(force_inline=false) p =
 			| _ ->
 				raise Exit
 		in
-		if not force_inline && f.cf_kind <> Method MethInline then raise Exit;
+		if not force_inline then begin
+			if f.cf_kind <> Method MethInline then raise Exit;
+		end else begin
+			delay ctx PFinal (fun () ->
+				if has_class_field_flag f CfOverridden then error (Printf.sprintf "Cannot force inline-call to %s because it is overridden" f.cf_name) p
+			);
+		end;
 		let config = match cl with
 			| Some ({cl_kind = KAbstractImpl _}) when Meta.has Meta.Impl f.cf_meta ->
 				let t = if f.cf_name = "_new" then

+ 2 - 1
src/typing/typeloadCheck.ml

@@ -160,7 +160,8 @@ let check_overriding ctx c f =
 			if (has_class_field_flag f2 CfFinal) then display_error ctx ("Cannot override final method " ^ i) p;
 			try
 				let t = apply_params csup.cl_params params t in
-				valid_redefinition ctx f f.cf_type f2 t
+				valid_redefinition ctx f f.cf_type f2 t;
+				add_class_field_flag f2 CfOverridden;
 			with
 				Unify_error l ->
 					display_error ctx ("Field " ^ i ^ " overloads parent class with different or incomplete type") p;

+ 16 - 0
tests/misc/projects/Issue7824/Main.hx

@@ -0,0 +1,16 @@
+class Base {
+	public function new() { }
+
+	public function test() { }
+}
+
+class Child extends Base {
+	override function test() { }
+}
+
+class Main {
+	static function main() {
+		var m = new Base();
+		inline m.test();
+	}
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:14: characters 3-18 : Cannot force inline-call to test because it is overridden