Fix: unused variables pass not taking into account `E_mod_in`
Motivation and Context
The passes unused
(for finding unused bindings) & muchused
(for checking linearity for tickets) did not decend into the declarations of E_mod_in
(location module in an expression).
Which caused unnecessary unused warnings for binding & no warnings in duplicate tickets.
Fixes #1672 (closed)
Description
This MR fixes these issues.
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
For a contract like
let fst (x, _) = x
let snd (_, x) = x
let main (_ : unit * nat ticket) : operation list * nat ticket =
let n = 10n in
module B = struct
let ticket = Option.unopt (Tezos.create_ticket n n)
let y = ticket, ticket
end in
[], Option.unopt (Tezos.join_tickets (fst B.y, snd B.y))
Before
ligo.60 compile contract y.mligo
File "y.mligo", line 6, characters 6-7:
5 | let main (_ : unit * nat ticket) : operation list * nat ticket =
6 | let n = 10n in
7 | module B = struct
:
Warning: unused variable "n".
Hint: replace it by "_n" to prevent this warning.
Error(s) occurred while type checking the contract:
Ill typed contract:
...
After
$ _build/install/default/bin/ligo compile contract y.mligo
File "y.mligo", line 8, characters 8-14:
7 | module B = struct
8 | let ticket = Option.unopt (Tezos.create_ticket n n)
9 | let y = ticket, ticket
:
Warning: variable "ticket" cannot be used more than once.
File "y.mligo", line 9, characters 4-26:
8 | let ticket = Option.unopt (Tezos.create_ticket n n)
9 | let y = ticket, ticket
10 | end in
:
Warning: variable "B.y" cannot be used more than once.
Error(s) occurred while type checking the contract:
Ill typed contract:
...
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha