Skip to content

Commit

Permalink
[typer] add -D warn-var-shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Oct 16, 2017
1 parent 58646af commit 2a8c22f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ let save_locals ctx =

let add_local ctx n t p =
let v = alloc_var n t p in
if Define.raw_defined ctx.com.defines "warn-var-shadowing" then begin
try
let v' = PMap.find n ctx.locals in
ctx.com.warning "This variable shadows a previously declared variable" p;
ctx.com.warning "Previous variable was here" v'.v_pos
with Not_found ->
()
end;
ctx.locals <- PMap.add n v ctx.locals;
v

Expand Down

0 comments on commit 2a8c22f

Please sign in to comment.