Browse Source

narrow error pos on invalid override (#9010)

Aleksandr Kuzmenko 6 years ago
parent
commit
518d019865

+ 12 - 3
src/typing/typeloadFields.ml

@@ -1362,11 +1362,20 @@ let init_field (ctx,cctx,fctx) f =
 		match (fst acc, f.cff_kind) with
 		match (fst acc, f.cff_kind) with
 		| APublic, _ | APrivate, _ | AStatic, _ | AFinal, _ | AExtern, _ -> ()
 		| APublic, _ | APrivate, _ | AStatic, _ | AFinal, _ | AExtern, _ -> ()
 		| ADynamic, FFun _ | AOverride, FFun _ | AMacro, FFun _ | AInline, FFun _ | AInline, FVar _ -> ()
 		| ADynamic, FFun _ | AOverride, FFun _ | AMacro, FFun _ | AInline, FFun _ | AInline, FVar _ -> ()
-		| _, FVar _ -> display_error ctx ("Invalid accessor '" ^ Ast.s_placed_access acc ^ "' for variable " ^ name) p
-		| _, FProp _ -> display_error ctx ("Invalid accessor '" ^ Ast.s_placed_access acc ^ "' for property " ^ name) p
+		| _, FVar _ -> display_error ctx ("Invalid accessor '" ^ Ast.s_placed_access acc ^ "' for variable " ^ name) (snd acc)
+		| _, FProp _ -> display_error ctx ("Invalid accessor '" ^ Ast.s_placed_access acc ^ "' for property " ^ name) (snd acc)
 	) f.cff_access;
 	) f.cff_access;
 	begin match fctx.override with
 	begin match fctx.override with
-		| Some _ -> (match c.cl_super with None -> error ("Invalid override on field '" ^ name ^ "': class has no super class") p | _ -> ());
+		| Some _ ->
+			(match c.cl_super with
+			| None ->
+				let p =
+					try List.assoc AOverride f.cff_access
+					with Not_found -> p
+				in
+				error ("Invalid override on field '" ^ name ^ "': class has no super class") p
+			| _ -> ()
+			);
 		| None -> ()
 		| None -> ()
 	end;
 	end;
 	begin match cctx.abstract with
 	begin match cctx.abstract with

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

@@ -0,0 +1 @@
+-main InvalidOverride

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

@@ -0,0 +1,2 @@
+InvalidOverride.hx:4: characters 2-10 : Invalid accessor 'override' for variable field
+InvalidOverride.hx:6: characters 20-24 : Field some is declared 'override' but doesn't override any field

+ 11 - 0
tests/misc/projects/Issue9010/InvalidOverride.hx

@@ -0,0 +1,11 @@
+class InvalidOverride extends Parent {
+	static function main() {}
+
+	override var field:String;
+
+	override function some():String {
+		return null;
+	}
+}
+
+class Parent {}