You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BEAM: nested module call mis-lowers as UFCS when a make method shares the name #182
A call to a nested module's function is mis-lowered on BEAM when any make block in the unit defines a method with the same name. The walker is correct; BEAM evaluates the module path as a value.
module Outer do
module Inner do
foul greet(name: String) -> String do
return "hi " + name
end
end
end
record Loud do end
make Loud do
foul greet(name: String) -> String = "HI " + name
end
foul use(n: String) -> String = Outer.Inner.greet(n)
main do
IO.printLine(use("x"))
end
walker: hi x
BEAM: runtime error: Undefined function: Outer.Inner
No capabilities are involved. Remove the make block and BEAM is correct again, so the trigger is purely the name collision.
Cause
The emitted Core shows the module path being evaluated as a value and the method applied UFCS-style to the result:
Once greet is a known receiver method, Outer.Inner.greet(n) resolves through the receiver/UFCS machinery instead of the module path, and the dotted receiver Outer.Inner is then lowered as an ordinary expression — which fails, because it is a module, not a value.
A bare receiver survives this: Outer.greet(n) resolves as a module path before UFCS gets a chance. Only a dotted receiver loses.
Why it matters beyond this repro
It is the blocker for nested capabilities in #143/#181. A capability always has both a module member and a same-named make method implementing it, so FS.File.read(path) collides by construction — and FS.File and FS.Directory are exactly the shapes the stdlib conversion needs.
Expected
A dotted path naming a module in the unit should resolve as a module-qualified call regardless of whether a make-block method shares the function's name, matching the walker.
Fixed. A dotted path naming a module of the compilation unit now wins over the resolved receiver method, so the call reaches the module instead of being lowered as a value.
The resolver picks the make-block method once one shares the name, and lowering follows that target faithfully — the dotted receiver is then lowered as an ordinary expression, which a module is not. There was already precedent for overriding a resolved target in exactly this way (localTypeShadows, localFieldAccessor), so the fix sits beside those: if modulePath yields two or more segments and moduleFunctions holds <path>.<method>, the module path owns the call.
Deliberately limited to dotted paths of two or more segments. A bare receiver never had the problem — it resolves as a module path before UFCS gets a chance — so nothing about single-segment behaviour changes.
Spec: spec/nested_module_method_collision.kex, running on both backends, and covering the reverse direction too (the make method must still reach its own receiver).
This also unblocked nested capabilities on BEAM (#181): spec/capabilities_nested.kex came off # kex: skip-beam. spec-beam went 259 → 261.
Activity
akoskovacs commentedon Aug 22, 2026
Fixed. A dotted path naming a module of the compilation unit now wins over the resolved receiver method, so the call reaches the module instead of being lowered as a value.
The resolver picks the make-block method once one shares the name, and lowering follows that target faithfully — the dotted receiver is then lowered as an ordinary expression, which a module is not. There was already precedent for overriding a resolved target in exactly this way (
localTypeShadows,localFieldAccessor), so the fix sits beside those: ifmodulePathyields two or more segments andmoduleFunctionsholds<path>.<method>, the module path owns the call.Deliberately limited to dotted paths of two or more segments. A bare receiver never had the problem — it resolves as a module path before UFCS gets a chance — so nothing about single-segment behaviour changes.
Spec:
spec/nested_module_method_collision.kex, running on both backends, and covering the reverse direction too (the make method must still reach its own receiver).This also unblocked nested capabilities on BEAM (#181):
spec/capabilities_nested.kexcame off# kex: skip-beam. spec-beam went 259 → 261.Fix nested module calls, resovles #182, #143