assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Empty arrays as inputs with omitted default context loose this context for some reason

Open MaxGraey opened this issue 3 years ago • 0 comments

Simple example:

class A<T> {
  foo<U extends ArrayLike<T> = Array<T>>(a: U): U {
    return a;
  }
}

const a = new A<string>();
const r = a.foo([]); // `r` should infer as Array<string> but it deduced as `Array<usize>` instead
// a.foo<string[]>([]) // <- works

export function check(): bool {
  return r instanceof Array<string>; // will return `false` instead `true`
}

AssemblyScript has a pessimistic rule. When empty array literal can't be inferred value type it presents this as usize instead any (TS-way). But this is not that situation.

MaxGraey avatar Aug 04 '22 13:08 MaxGraey