Morpho-lang / Morpho-lang/morpho
Importing a module before its consumer drops earlier arity overloads inside the consumer
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 153
- Forks
- 22
- Avg merge
- 9d 10h
- Merged PRs (30d)
- 1
Description
@ -0,0 +1,73 @@
Title
[Bug] Importing a module before its consumer drops earlier arity overloads inside the consumer
Body
Describe the bug
If a module defines an arity-overloaded function and a second module imports it, call sites in the consumer only see the last overload when the provider was already imported earlier in the session. Global call sites still see every overload.
Morpho version
0.6.4
To Reproduce
Two modules:
arity_provider.morpho:
fn f(x) { return "1-arg" }
fn f(x, y) { return "2-arg" }
arity_consumer.morpho:
import arity_provider
fn call1() { return f(0) }
fn call2() { return f(0, 1) }
OK script:
import arity_consumer
print call2()
print call1()
BUG script:
import arity_provider
import arity_consumer
print call2()
print call1()
Expected behavior
Both scripts print:
2-arg
1-arg
Actual behavior
OK script works. BUG script prints:
2-arg
Error 'InvldArgs': Expected 2 arguments but got 1.
from f ... in arity_consumer.morpho
from call1 ...
After the same imports, f(0) at global scope still succeeds — only call sites compiled inside the consumer are broken.
Additional context
- Trigger is import order: provider already loaded before the consumer is compiled/imported.
import arity_consumeralone (provider loaded only as a dependency) is fine.- Real-world hit:
import xgraphics/import xcolorbeforeimport xplot, thenGray(0.5)insidexplotfails whileGray(0.5, 1)works (Grayis defined asGray(x)/Gray(x, a)inxcolor). - Related flavor of import-order MD issues: #303.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with arity_provider.morpho and arity_consumer.morpho, comparing the two import orders shown in the report. Start by tracing how imports and arity-overloaded functions are compiled for consumer call sites. Done means both scripts print 2-arg followed by 1-arg, while global calls remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100