Browse Source

[typer] don't shadow-warn for generated locals

closes #10819
Simon Krajewski 2 years ago
parent
commit
3b0c0b3922

+ 12 - 7
src/context/typecore.ml

@@ -287,14 +287,19 @@ let save_locals ctx =
 let add_local ctx k n t p =
 	let v = alloc_var k n t p in
 	if Define.defined ctx.com.defines Define.WarnVarShadowing && n <> "_" then begin
-		try
-			let v' = PMap.find n ctx.locals in
-			(* ignore std lib *)
-			if not (List.exists (ExtLib.String.starts_with p.pfile) ctx.com.std_path) then begin
-				warning ctx WVarShadow "This variable shadows a previously declared variable" p;
-				warning ctx WVarShadow (compl_msg "Previous variable was here") v'.v_pos
+		match k with
+		| VUser _ ->
+			begin try
+				let v' = PMap.find n ctx.locals in
+				(* ignore std lib *)
+				if not (List.exists (ExtLib.String.starts_with p.pfile) ctx.com.std_path) then begin
+					warning ctx WVarShadow "This variable shadows a previously declared variable" p;
+					warning ctx WVarShadow (compl_msg "Previous variable was here") v'.v_pos
+				end
+			with Not_found ->
+				()
 			end
-		with Not_found ->
+		| _ ->
 			()
 	end;
 	ctx.locals <- PMap.add n v ctx.locals;

+ 10 - 0
tests/misc/projects/Issue10819/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+	static var a:Array<Int> = [1];
+
+	static function main() {
+		switch a { // <--- Warning : (WVarShadow) This variable shadows a previously declared variable
+			case [1]:
+			case _:
+		}
+	}
+}

+ 3 - 0
tests/misc/projects/Issue10819/compile.hxml

@@ -0,0 +1,3 @@
+--main Main
+--interp
+-D warn-var-shadowing

+ 0 - 0
tests/misc/projects/Issue10819/compile.hxml.stderr