Skip to content

dart2js has incomplete support for local function type variables #42088

@fishythefish

Description

@fishythefish

Consider the following contrived, but small, example:

class Foo<T> {}

void main() {
  <T>() => Foo<T>().runtimeType;
}

The VM compiles this successfully. (You can, for example, print the local function to ensure liveness.)

On dart2js, the compiler throws:

The compiler crashed: Assertion failure: Local function type variables are not supported.
#0      failedAt (package:compiler/src/diagnostics/invariant.dart:49:3)
#1      JsToFrontendMapImpl.toBackendTypeVariable (package:compiler/src/js_model/js_world_builder.dart:712:7)
#2      JsToFrontendMapImpl.toBackendEntity (package:compiler/src/js_model/js_world_builder.dart:689:14)
#3      _TypeConverter.visitTypeVariableType (package:compiler/src/js_model/js_world_builder.dart:792:49)
#4      TypeVariableType.accept (package:compiler/src/elements/types.dart:414:15)
#5      _TypeConverter.visit (package:compiler/src/js_model/js_world_builder.dart:751:17)
#6      _TypeConverter.visitLegacyType (package:compiler/src/js_model/js_world_builder.dart:764:29)
#7      LegacyType.accept (package:compiler/src/elements/types.dart:234:15)
#8      _TypeConverter.visit (package:compiler/src/js_model/js_world_builder.dart:751:17)
#9      _TypeConverter.visitList (package:compiler/src/js_model/js_world_builder.dart:757:16)
#10     _TypeConverter.visitInterfaceType (package:compiler/src/js_model/js_world_builder.dart:786:34)
#11     InterfaceType.accept (package:compiler/src/elements/types.dart:354:15)
#12     _TypeConverter.visit (package:compiler/src/js_model/js_world_builder.dart:751:17)
#13     JsToFrontendMapImpl.toBackendType (package:compiler/src/js_model/js_world_builder.dart:683:16)
#14     JsClosedWorldBuilder._convertBackendUsage.<anonymous closure> (package:compiler/src/js_model/js_world_builder.dart:256:15)
#15     MappedIterator.moveNext (dart:_internal/iterable.dart:392:20)
#16     SetMixin.addAll (dart:collection/set.dart:57:23)
#17     new LinkedHashSet.of (dart:collection/linked_hash_set.dart:111:27)
#18     Iterable.toSet (dart:core/iterable.dart:416:21)
#19     JsClosedWorldBuilder._convertBackendUsage (package:compiler/src/js_model/js_world_builder.dart:258:8)
#20     JsClosedWorldBuilder.convertClosedWorld (package:compiler/src/js_model/js_world_builder.dart:66:9)
#21     JsBackendStrategy.createJClosedWorld (package:compiler/src/js_model/js_strategy.dart:180:52)
...

Although local type variables cannot be (globally) indexed, it should be possible to convert them from the K-model to the J-model by first ensuring the enclosing local function is converted and indexing into its type variables.

/cc @johnniwinther

Metadata

Metadata

Assignees

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2js

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions