Explorar o código

narrow pos for "name is already defined in module" errors (closes #9631)

Aleksandr Kuzmenko %!s(int64=5) %!d(string=hai) anos
pai
achega
e89879a1b3

+ 5 - 5
src/typing/typeloadModule.ml

@@ -200,10 +200,10 @@ let module_pass_1 ctx m tdecls loadp =
 			error "Previous declaration here" prev_pos;
 		in
 		List.iter (fun (t2,(_,p2)) ->
-			if snd (t_path t2) = name then error p2
+			if snd (t_path t2) = name then error (t_infos t2).mt_name_pos
 		) !decls;
-		List.iter (fun (d,p) ->
-			if fst d.d_name = name then error p
+		List.iter (fun (d,_) ->
+			if fst d.d_name = name then error (snd d.d_name)
 		) !statics
 	in
 	let make_path name priv p =
@@ -222,7 +222,7 @@ let module_pass_1 ctx m tdecls loadp =
 			if !has_declaration then error "import and using may not appear after a declaration" p;
 			acc
 		| EStatic d ->
-			check_name (fst d.d_name) p;
+			check_name (fst d.d_name) (snd d.d_name);
 			has_declaration := true;
 			statics := (d,p) :: !statics;
 			acc;
@@ -230,7 +230,7 @@ let module_pass_1 ctx m tdecls loadp =
 			let name = fst d.d_name in
 			has_declaration := true;
 			let priv = List.mem HPrivate d.d_flags in
-			let path = make_path name priv p in
+			let path = make_path name priv (snd d.d_name) in
 			let c = mk_class m path p (pos d.d_name) in
 			(* we shouldn't load any other type until we propertly set cl_build *)
 			c.cl_build <- (fun() -> error (s_type_path c.cl_path ^ " is not ready to be accessed, separate your type declarations in several files") p);

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

@@ -1,2 +1,2 @@
 Foo.hx:2: characters 1-18 : Name A is already defined in this module
-Foo.hx:1: characters 1-16 : Previous declaration here
+Foo.hx:1: characters 9-10 : Previous declaration here

+ 7 - 0
tests/misc/projects/Issue9631/Fields.hx

@@ -0,0 +1,7 @@
+function main() {
+
+}
+
+function main() {
+
+}

+ 9 - 0
tests/misc/projects/Issue9631/Types.hx

@@ -0,0 +1,9 @@
+class Types {
+	static function main() {
+
+	}
+}
+
+class Types {
+
+}

+ 1 - 0
tests/misc/projects/Issue9631/compile-fields-fail.hxml

@@ -0,0 +1 @@
+-main Fields

+ 2 - 0
tests/misc/projects/Issue9631/compile-fields-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Fields.hx:5: characters 10-14 : Name main is already defined in this module
+Fields.hx:1: characters 10-14 : Previous declaration here

+ 1 - 0
tests/misc/projects/Issue9631/compile-types-fail.hxml

@@ -0,0 +1 @@
+-main Types

+ 2 - 0
tests/misc/projects/Issue9631/compile-types-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Types.hx:7: characters 7-12 : Name Types is already defined in this module
+Types.hx:1: characters 7-12 : Previous declaration here