Skip to content

Commit

Permalink
Reuse usage table for env continuation
Browse files Browse the repository at this point in the history
Fixes a bug where after a `use` declaration in functions, unused
bindings weren't reported correctly
  • Loading branch information
tjammer committed Feb 12, 2024
1 parent a213fab commit 4679300
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,12 @@ let fix_scope_loc scope loc =
{ scope with kind }

let use_module env loc name =
let tbl =
let scope, _ = decap_exn env in
match scope.kind with
| Stoplevel tbl | Sfunc tbl | Scont tbl -> tbl
| Smodule _ -> failwith "Unexpected module"
in
let scope =
find_general
~find:(fun key scope -> Map.find_opt key scope.modules)
Expand All @@ -794,7 +800,7 @@ let use_module env loc name =
|> fun scope -> fix_scope_loc scope loc
in

let cont = empty_scope (Scont (Hashtbl.create 64)) in
let cont = empty_scope (Scont tbl) in
{ env with values = cont :: scope :: env.values }

let add_callname ~key cname env =
Expand Down
5 changes: 5 additions & 0 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ Use module name prefix for function names to prevent linker dups
2 | fun specific_name(): ()
^^^^^^^^^^^^^

nameclash_use.smu:2.5-18: warning: Unused binding specific_name.

2 | fun specific_name(): ()
^^^^^^^^^^^^^

Distinguish closures and functions
$ schmu decl_lambda.smu -m
$ schmu use_lambda.smu
Expand Down

0 comments on commit 4679300

Please sign in to comment.