Skip to content

dart2js type bounds tasks #33037

@rakudrama

Description

@rakudrama

Generic types should to display type parameters, even when dynamic or missing.
Types are displayed via o.runtimeType and in TypeError (CastError) messages.

When displayed in a TypeError message, the type parameters may have been erased:

class Foo<T extends num> {}
main() {
  dynamic f = new Foo<int>();
  List<String> a = f;
}

When Foo.T has been erased, should the message display without the types, or with the defaulted (incorrect) bounds, or some indicator?

TypeError: Instance of 'Foo': type 'Foo' is not a subtype of type 'List<String>'
TypeError: Instance of 'Foo<num>': type 'Foo<num>' is not a subtype of type 'List<String>'
TypeError: Instance of 'Foo<?>': type 'Foo<?>' is not a subtype of type 'List<String>'

I think we will go with the raw type for now.

Types will be present if o.runtimeType is present. We will need to revisit this topic if we allow erasure and o.runtimeType, or if we implement partial (allocation-site specific) erasure.

  • Change printed raw types
    • JSArray might still usefully print asJSArray<dynamic> from a Dart allocation and JSArray for allocations from interop code. If the array instance has type parameter erasure, we can't tell the difference!
  • Handle types optimized by erasing types
  • Default-to-bound in forwarding stubs dart2js: Incorrect type variable bounds in argument defaulting stubs #32741
  • Type literals
    • Change type literals like Set to print as Set<dynamic>.
    • Default types to bound in type literals. Foo is Foo<num> in class Foo<T extends num> {}
    • If the type has erased type parameters, omit the type parameters.
    • Ensure new Foo().runtimeType == Foo is always true.

Metadata

Metadata

Labels

P2A bug or feature request we're likely to work onarea-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.web-dart2js

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions