1
Vote

generic bug

description

consider the following class.
class GenericPractice<T extends CouponInfo>{
    private entity: T;
    constructor(entity: T) {
        this.entity = entity;
    }

    public add(item: T): string {
        return item.toString();
    }

}
class CouponInfo {
    public toString(): string {
        return "couponInfo";
    }
}
class Snake{
}
when we use the following code
 var genericPractice = new GenericPractice(new CouponInfo());
genericPractice.add(new Snake("Sammy the Python")));
theoretically, this line:
 genericPractice.add(new Snake("Sammy the Python")));
should have compile time error since Snake doesn't extend CouponInfo.

However, the compile pass which violates the fundamental concept of generic.

comments