Skip to content

The type is misordered when use abstract generic class #1877

Closed
@yjhmelody

Description

@yjhmelody

See https://github.com/jtenner/as-pect/issues/349

ERROR TS2322: Type '(this: assembly/UInt/UInt32/UInt32) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u64>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt32.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt64/UInt64) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u32>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt64.ts(21,5)

The above types are swapped.

The quantities of the various types below are correct, but they do not match the types.

ERROR TS2322: Type '(this: assembly/UInt/UInt16/UInt16) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u64>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt16.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt32/UInt32) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u64>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt32.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt16/UInt16) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u32>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt16.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt64/UInt64) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u32>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt64.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt32/UInt32) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u16>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt32.ts(21,5)

ERROR TS2322: Type '(this: assembly/UInt/UInt64/UInt64) => i32' is not assignable to type '(this: assembly/AbstractInt/AbstractInt<u16>) => i32'.

     _byteLength(): i32 {
     ~~~~~~~~~~~
 in assembly/UInt/UInt64.ts(21,5)

I reproduce it using asc, so it's as bug.

This is a minimal example:

export abstract class AbstractInt<T> {
    protected _value: T;

    constructor(value: T) {
        this._value = value;
    }

    get _byteLength(): i32 {
        return 0;
    }

    @inline
    encodedLength(): i32 {
        return this._byteLength;
    }
}

export class UInt8 extends AbstractInt<u8> {
    @inline
    get _byteLength(): i32 {
        return 1;
    }

    constructor(value: u8 = 0) {
        super(value);
    }
}

export class Int8 extends AbstractInt<i8> {
    @inline
    get _byteLength(): i32 {
        return 1;
    }

    constructor(value: u8 = 0) {
        super(value);
    }
}
  • Still the same phenomenon, if these types appear in one file, an error will occur.
  • If sub class overload encodedLength, the error don't happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions