asoffer / Icarus

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

Operator overloading is broken #58

Closed perimosocordiae closed 2 years ago

perimosocordiae commented 3 years ago

Or at least, it's not working the way I would expect it to. Reproducer:

io ::= import "io.ic"

foo ::= struct {
  a: i64
}

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

(+) ::= add

p := foo.{ a = 3 }
q := foo.{ a = 4 }

res1 := add(p, q)
io.Print(res1.a)
io.Print("\n")

res2 := p + q
io.Print(res2.a)
io.Print("\n")

Observed output:

7
1