MOD007: Duplicate module-scope binding (let/func same name)
Code: MOD007
Category: Module system
Since: v0.30.0 (M-MODULE-LET-FUNC-RESOLUTION, #366)
What this error means
A module-scope name is declared more than once: as both a module-level let/letrec
and a func, or as two module-level lets. Since module lets and funcs now share one
unified declaration space (so a let value can call a module func and vice versa), a name with
two bindings is ambiguous. This was previously accepted silently with undefined shadowing
semantics — a soundness trap — and is now a loud compile error that names both declaration
positions.
Example
module bench/solution
let helper = 5 -- ← binding 1
export func helper() -> int = 10 -- ← binding 2, same name
export func main() -> int = helper()
Error MOD007: 'helper' is declared as both a module-level let (at 3:1) and a func (at 4:8)
— a module-scope name may have only one binding.
Fix: rename one of them, or fold the let into the func body
The two-let form is caught the same way:
module bench/solution
let dup = 5
let dup = 6 -- Error MOD007: module-level let 'dup' is declared twice
export func main() -> int = dup
How to fix
- Rename one binding so each module-scope name is unique.
- Fold the
letinto thefuncif they were meant to be the same value — e.g. replace alet x = …used only inside one func with a locallet x = … in …, or make the value the func's body.
Background
Before this change (#366), a module-level let value could never see a module func, and a
let/func name collision compiled silently. Making module lets first-class nodes of the SCC
call-graph fixed the resolution bug and simultaneously exposed the collision as ambiguous, so it
is now pinned by MOD007 rather than left to undefined shadowing. A scan of the shipped examples
and stdlib found no program relying on the old silent behavior.