Browse Source

narrow error pos on inheritance/implementation mismatch
(closes #9010)

Aleksandr Kuzmenko 5 years ago
parent
commit
8de4422d94

+ 14 - 10
src/typing/typeloadCheck.ml

@@ -149,14 +149,18 @@ let get_native_name meta =
 		error "String expected" mp
 		error "String expected" mp
 
 
 let check_native_name_override ctx child base =
 let check_native_name_override ctx child base =
-	let error() =
-		display_error ctx ("Field " ^ child.cf_name ^ " has different @:native value than in superclass") child.cf_pos;
-		display_error ctx ("Base field is defined here") base.cf_pos
+	let error base_pos child_pos =
+		display_error ctx ("Field " ^ child.cf_name ^ " has different @:native value than in superclass") child_pos;
+		display_error ctx ("Base field is defined here") base_pos
 	in
 	in
 	try
 	try
-		let native_name = fst (get_native_name child.cf_meta) in
-		try if fst (get_native_name base.cf_meta) <> native_name then error()
-		with Not_found -> error()
+		let child_name, child_pos = get_native_name child.cf_meta in
+		try
+			let base_name, base_pos = get_native_name base.cf_meta in
+			if base_name <> child_name then
+				error base_pos child_pos
+		with Not_found ->
+			error base.cf_name_pos child_pos
 	with Not_found -> ()
 	with Not_found -> ()
 
 
 let check_overriding ctx c f =
 let check_overriding ctx c f =
@@ -165,7 +169,7 @@ let check_overriding ctx c f =
 		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
 		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 *)
 	| _ 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) ->
 	| Some (csup,params) ->
-		let p = f.cf_pos in
+		let p = f.cf_name_pos in
 		let i = f.cf_name in
 		let i = f.cf_name in
 		let check_field f get_super_field is_overload = try
 		let check_field f get_super_field is_overload = try
 			(if is_overload && not (Meta.has Meta.Overload f.cf_meta) then
 			(if is_overload && not (Meta.has Meta.Overload f.cf_meta) then
@@ -197,7 +201,7 @@ let check_overriding ctx c f =
 			with
 			with
 				Unify_error l ->
 				Unify_error l ->
 					display_error ctx ("Field " ^ i ^ " overrides parent class with different or incomplete type") p;
 					display_error ctx ("Field " ^ i ^ " overrides parent class with different or incomplete type") p;
-					display_error ctx ("Base field is defined here") f2.cf_pos;
+					display_error ctx ("Base field is defined here") f2.cf_name_pos;
 					display_error ctx (error_msg (Unify l)) p;
 					display_error ctx (error_msg (Unify l)) p;
 		with
 		with
 			Not_found ->
 			Not_found ->
@@ -332,7 +336,7 @@ module Inheritance = struct
 		| _ -> error "Should extend by using a class" p
 		| _ -> error "Should extend by using a class" p
 
 
 	let rec check_interface ctx c intf params =
 	let rec check_interface ctx c intf params =
-		let p = c.cl_pos in
+		let p = c.cl_name_pos in
 		let rec check_field i f =
 		let rec check_field i f =
 			(if ctx.com.config.pf_overload then
 			(if ctx.com.config.pf_overload then
 				List.iter (function
 				List.iter (function
@@ -356,7 +360,7 @@ module Inheritance = struct
 						h.interface_field_implementations <- (intf,f,c,Some f2) :: h.interface_field_implementations;
 						h.interface_field_implementations <- (intf,f,c,Some f2) :: h.interface_field_implementations;
 				end;
 				end;
 				ignore(follow f2.cf_type); (* force evaluation *)
 				ignore(follow f2.cf_type); (* force evaluation *)
-				let p = (match f2.cf_expr with None -> p | Some e -> e.epos) in
+				let p = f2.cf_name_pos in
 				let mkind = function
 				let mkind = function
 					| MethNormal | MethInline -> 0
 					| MethNormal | MethInline -> 0
 					| MethDynamic -> 1
 					| MethDynamic -> 1

+ 1 - 0
tests/misc/projects/Issue9010/ChildFields-fail.hxml

@@ -0,0 +1 @@
+-main ChildFields

+ 2 - 0
tests/misc/projects/Issue9010/ChildFields-fail.hxml.stderr

@@ -0,0 +1,2 @@
+ChildFields.hx:4: characters 18-28 : Field noOverride should be declared with 'override' since it is inherited from superclass Parent
+ChildFields.hx:7: characters 27-34 : Field inlined is inlined and cannot be overridden

+ 19 - 0
tests/misc/projects/Issue9010/ChildFields.hx

@@ -0,0 +1,19 @@
+class ChildFields extends Parent {
+	static function main() {}
+
+	public function noOverride():String {
+		return null;
+	}
+	override public function inlined():String {
+		return null;
+	}
+}
+
+class Parent {
+	public function noOverride():String {
+		return null;
+	}
+	public inline function inlined():String {
+		return null;
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9010/InterfaceFields-fail.hxml

@@ -0,0 +1 @@
+-main InterfaceFields

+ 3 - 0
tests/misc/projects/Issue9010/InterfaceFields-fail.hxml.stderr

@@ -0,0 +1,3 @@
+InterfaceFields.hx:1: characters 7-22 : Field missing needed by IFace is missing
+InterfaceFields.hx:4: characters 13-24 : Field wrongAccess has different property access than in IFace ((never,null) should be (default,null))
+InterfaceFields.hx:5: characters 18-27 : Field wrongKind has different property access than in IFace (method should be var)

+ 14 - 0
tests/misc/projects/Issue9010/InterfaceFields.hx

@@ -0,0 +1,14 @@
+class InterfaceFields implements IFace {
+	static function main() {}
+
+	public var wrongAccess(never,null):String;
+	public function wrongKind():String {
+		return null;
+	}
+}
+
+interface IFace {
+	var missing:String;
+	var wrongAccess(default,null):String;
+	var wrongKind:String;
+}

+ 1 - 0
tests/misc/projects/Issue9010/NativeMeta-fail.hxml

@@ -0,0 +1 @@
+-main NativeMeta

+ 6 - 0
tests/misc/projects/Issue9010/NativeMeta-fail.hxml.stderr

@@ -0,0 +1,6 @@
+NativeMeta.hx:4: characters 11-24 : Field some has different @:native value than in superclass
+NativeMeta.hx:16: characters 11-25 : Base field is defined here
+NativeMeta.hx:1: lines 1-13 : Defined in this class
+NativeMeta.hx:9: characters 11-25 : Field noNative has different @:native value than in superclass
+NativeMeta.hx:20: characters 18-26 : Base field is defined here
+NativeMeta.hx:1: lines 1-13 : Defined in this class

+ 22 - 0
tests/misc/projects/Issue9010/NativeMeta.hx

@@ -0,0 +1,22 @@
+class Main extends Parent {
+	static function main() {}
+
+	@:native('childNative')
+	override function some() {
+		super.some();
+	}
+
+	@:native('childNative2')
+	override function noNative() {
+		super.noNative();
+	}
+}
+
+class Parent {
+	@:native('parentNative')
+	public function some() {
+	}
+
+	public function noNative() {
+	}
+}