assemblyscript
assemblyscript copied to clipboard
Why implementing a method without consistent type args is legal?
interface Foo {
foo<T>(): void
}
class Bar implements Foo {
foo(): void {}
}
let bar: Foo = new Bar;
It works.
It also works in TS
How about this?
interface Foo {
foo<T>(t: T): void
}
class Bar implements Foo {
foo(t: i32): void {
}
}
class Baz implements Foo {
foo(t: i8): void {
}
}
let bar: Foo = new Bar;
let baz: Foo = new Baz;
bar.foo(1);
baz.foo(1);
Whoops, the AssemblyScript compiler has crashed during compile :-(
▌
▌ Here is a stack trace that may or may not be useful:
Good point
Shouldn't the type arg be inferred?
Yup. It should.
But the interface could not support dynamic dispatch if there are generic type in methods.