Skip to content

Commit

Permalink
[typer] don't shadow-warn for generated locals
Browse files Browse the repository at this point in the history
closes #10819
  • Loading branch information
Simn committed Nov 7, 2022
1 parent 321dffa commit 3b0c0b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/misc/projects/Issue10819/Main.hx
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions tests/misc/projects/Issue10819/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--main Main
--interp
-D warn-var-shadowing
Empty file.

0 comments on commit 3b0c0b3

Please sign in to comment.