Skip to content

dart2js: support type parameters in constant casts #32811

Closed
@sigmundch

Description

@sigmundch

This example:

class A { const A(); }
class B implements A { const B(); }

class M<T extends A> {
  final T a;
  const M(dynamic t): a = t;
}
main() {
  print(const M<B>(const B()));
}

Incorrectly fails with:

Error: `const B()` of type 'B' is not a subtype of M.T.
  print(const M<B>(const B()));
              ^

This is the same reason why this code fails too:

class M<T extends num> {
  final T a;
  const M(T t): a = -t * 0;
}
main() {
  print(const M(2.1));
}

because t*0 is a closed operation (returns int or double depending on the input type).

The latter is found in core types like Rectangle in dart:math.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failuresweb-dart2js

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions