Morpho-lang / Morpho-lang/morpho

Importing a module before its consumer drops earlier arity overloads inside the consumer

Open
#337 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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_consumer alone (provider loaded only as a dependency) is fine.
  • Real-world hit: import xgraphics / import xcolor before import xplot, then Gray(0.5) inside xplot fails while Gray(0.5, 1) works (Gray is defined as Gray(x) / Gray(x, a) in xcolor).
  • Related flavor of import-order MD issues: #303.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.