Skip to content

generic infer error in special case #2166

Closed

Description

@HerrCai0907

This code cannot compile. It seems like generic infer error.
In subscribe<T>, T is AAAAAA; In fieldparam.reduce, T is string. But compiler cannot distinguish them.

function subscribe<T>(): void {
    let a = new TestClass2(new Array<string>(10));
}

class TestClass2 {
    constructor(fieldparam: Array<string>) {
        function reducefunc(total: i32, curr: string, index: i32, array: Array<string>): i32 {
            return 0;
        }
        fieldparam.reduce(reducefunc, 0);
    }
}

class AAAAAA {}

subscribe<AAAAAA>();
ERROR TS2322: Type '(i32, ~lib/string/String, i32, ~lib/array/Array<~lib/string/String>) => i32' is not assignable to type '(i32, assembly/index/AAAAAA, i32, ~lib/array/Array<assembly/index/AAAAAA>) => i32'.

         fieldparam.reduce(reducefunc, 0);
                           ~~~~~~~~~~
 in assembly/index.ts(10,27)

ERROR TS2322: Type '~lib/array/Array<~lib/string/String>' is not assignable to type '~lib/array/Array<assembly/index/AAAAAA>'.

       acc = fn(acc, load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
                                                                              ~~~~
 in ~lib/array.ts(325,78)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy