asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

Operator overloading doesn't work across modules #83

Closed perimosocordiae closed 2 years ago

perimosocordiae commented 2 years ago

Here's a short reproducer.

File 1: test_mod.ic

#{export}
foo ::= struct {
  #{export}
  a: i64
}

#{export}
(+) ::= (x: foo, y: foo) -> foo {
  return foo.{ a = x.a + y.a }
}

File 2: test.ic

test :: = import "test_mod.ic"

f1 := test.foo.{ a = 1 }
f2 := test.foo.{ a = 2 }
res := f1 + f2

Error message:

Error in test.ic:
No matching binary operator (+) for types `test.foo` and `test.foo`.

  21 | res2 := f1 + f2

Note: if you copy-paste the contents of test_mod.ic into test.ic, then everything works as intended.