assemblyscript
assemblyscript copied to clipboard
Compiler crashes when use overloaded method with extra args
Example:
class Vec2 {
constructor(public x: f64 = 0, public y: f64 = 0) {}
@operator("==")
eq(a: Vec2, b: Vec2): bool { // non-static but 2 args
return a.x == b.x && a.y == b.y;
}
}
class Expect<T> {
constructor(public actual: T) {}
public toBe(expected: T): bool {
let actual = this.actual;
return actual == expected;
}
}
const exp = new Expect<Vec2>(new Vec2(1, 2));
assert(exp.toBe(new Vec2(1, 2)) == true);
will crash compiler.
However this will work:
class Vec2 {
constructor(public x: f64 = 0, public y: f64 = 0) {}
@operator("==")
eq(other: Vec2): bool { // 1 arg
return this.x == this.x && other.y == other.y;
}
}
or this:
class Vec2 {
constructor(public x: f64 = 0, public y: f64 = 0) {}
@operator("==")
static eq(a: Vec2, b: Vec2): bool { // 2 args but static
return a.x == a.x && b.y == b.y;
}
}