assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Why implementing a method without consistent type args is legal?

Open yjhmelody opened this issue 2 years ago • 6 comments

interface Foo {
    foo<T>(): void
}

class Bar implements Foo {
    foo(): void {}
}

let bar: Foo = new Bar; 

It works.

yjhmelody avatar Jul 09 '21 05:07 yjhmelody

It also works in TS

MaxGraey avatar Jul 09 '21 05:07 MaxGraey

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:

yjhmelody avatar Jul 09 '21 05:07 yjhmelody

Good point

MaxGraey avatar Jul 09 '21 06:07 MaxGraey

Shouldn't the type arg be inferred?

willemneal avatar Jul 09 '21 14:07 willemneal

Yup. It should.

JairusSW avatar Jul 09 '21 18:07 JairusSW

But the interface could not support dynamic dispatch if there are generic type in methods.

yjhmelody avatar Jul 07 '22 16:07 yjhmelody