فهرست منبع

[typer] remove CfOverridden, check override status through cl_descendants

closes #8738
Simon Krajewski 6 سال پیش
والد
کامیت
d868aeeed1

+ 0 - 1
src/core/type.ml

@@ -383,7 +383,6 @@ type flag_tclass_field =
 	| CfPublic
 	| CfExtern (* This is only set if the field itself is extern, not just the class. *)
 	| CfFinal
-	| CfOverridden
 	| CfModifiesThis (* This is set for methods which reassign `this`. E.g. `this = value` *)
 
 (* Flags *)

+ 12 - 3
src/typing/calls.ml

@@ -31,9 +31,18 @@ let make_call ctx e params t ?(force_inline=false) p =
 		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
-			);
+			match cl with
+			| None ->
+				()
+			| Some c ->
+				(* Delay this to filters because that's when cl_descendants is set. *)
+				ctx.com.callbacks#add_before_save (fun () ->
+					let rec has_override c =
+						List.exists (fun cf -> cf.cf_name = f.cf_name) c.cl_overrides
+						|| List.exists has_override c.cl_descendants
+					in
+					if List.exists has_override c.cl_descendants 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 ->

+ 0 - 1
src/typing/typeloadCheck.ml

@@ -194,7 +194,6 @@ let check_overriding ctx c f =
 			try
 				let t = apply_params csup.cl_params params t in
 				valid_redefinition ctx f f.cf_type f2 t;
-				add_class_field_flag f2 CfOverridden;
 			with
 				Unify_error l ->
 					display_error ctx ("Field " ^ i ^ " overrides parent class with different or incomplete type") p;

+ 14 - 0
tests/server/src/Main.hx

@@ -217,6 +217,20 @@ class ServerTests extends HaxeServerTestCase {
 		var counter = vfs.getContent("counter.txt");
 		utest.Assert.equals('2', counter);
 	}
+
+	function testIssue8738() {
+		vfs.putContent("Base.hx", getTemplate("issues/Issue8738/Base.hx"));
+		vfs.putContent("Main.hx", getTemplate("issues/Issue8738/Main1.hx"));
+		var args = ["-main", "Main", "--interp"];
+		runHaxe(args);
+		assertSuccess();
+		vfs.putContent("Main.hx", getTemplate("issues/Issue8738/Main2.hx"));
+		runHaxe(args);
+		assertErrorMessage("Main.hx:8: characters 3-21 : Cannot force inline-call to test because it is overridden");
+		vfs.putContent("Main.hx", getTemplate("issues/Issue8738/Main3.hx"));
+		runHaxe(args);
+		assertSuccess();
+	}
 }
 
 class Main {

+ 5 - 0
tests/server/test/templates/issues/Issue8738/Base.hx

@@ -0,0 +1,5 @@
+class Base {
+	public function new() {}
+
+	public function test() {}
+}

+ 9 - 0
tests/server/test/templates/issues/Issue8738/Main1.hx

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

+ 10 - 0
tests/server/test/templates/issues/Issue8738/Main2.hx

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

+ 6 - 0
tests/server/test/templates/issues/Issue8738/Main3.hx

@@ -0,0 +1,6 @@
+class Main {
+	static public function main() {
+		var base = new Base();
+		inline base.test();
+	}
+}