Преглед изворни кода

fix override checks (closes #6699)

Simon Krajewski пре 7 година
родитељ
комит
10515b6be6

+ 5 - 2
src/typing/typeload.ml

@@ -867,7 +867,7 @@ let copy_meta meta_src meta_target sl =
 let check_overriding ctx c f =
 	match c.cl_super with
 	| None ->
-		display_error ctx ("Field " ^ f.cf_name ^ " is declared 'override' but doesn't override any field") f.cf_pos
+		if List.memq f c.cl_overrides then display_error ctx ("Field " ^ f.cf_name ^ " is declared 'override' but doesn't override any field") f.cf_pos
 	| _ when c.cl_extern && Meta.has Meta.CsNative c.cl_meta -> () (* -net-lib specific: do not check overrides on extern CsNative classes *)
 	| Some (csup,params) ->
 		let p = f.cf_pos in
@@ -2585,7 +2585,10 @@ module ClassInitializer = struct
 						cf.cf_type <- t
 					| _ ->
 						let e , fargs = type_function ctx args ret fmode fd fctx.is_display_field p in
-						if fctx.is_override then check_overriding ctx c cf;
+						begin match fctx.field_kind with
+						| FKNormal when not fctx.is_static -> check_overriding ctx c cf
+						| _ -> ()
+						end;
 						(* Disabled for now, see https://github.com/HaxeFoundation/haxe/issues/3033 *)
 						(* List.iter (fun (v,_) ->
 							if v.v_name <> "_" && has_mono v.v_type then ctx.com.warning "Uninferred function argument, please add a type-hint" v.v_pos;

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

@@ -0,0 +1,16 @@
+class A {
+	function foo() {
+	}
+}
+
+class B extends A {
+	function foo() {
+	}
+}
+
+class Main {
+
+	static function main() {
+	}
+
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:7: lines 7-8 : Field foo should be declared with 'override' since it is inherited from superclass A