Skip to content

CFE fails to do constant spreads with extension typed elements #54357

Closed
@lrhn

Description

@lrhn

Example:

void main() {
  const ex3 = ExInt(3);
  const ex4 = ExInt(4);
  const l3 = [ex3];
  const l4 = [ex4];
  const l34i = [ex3 as int, ... l4 as List<int>]; // Works

  const l43 = [ex4, ex3]; // Works
  
  //  Info: Expected constant '3' to be of type 'ExInt', but was of type 'int'.
  const l3s4 = [ex3, ... l4]; // Fails to compile.
  //           ^  

  // Info: Expected constant '4' to be of type 'ExInt', but was of type 'int'.
  const ls43 = [... l4, ex3]; // Fails to compile.
  //                ^  

  // Info: Expected constant '3' to be of type 'ExInt', but was of type 'int'.
  const ls3s4 = [... l3, ... l4]; // Fails to compile.
  //                 ^  
}
extension type const ExInt(int _) implements int {}

Both VM and dart2js give similar error messages (dart2js uses web numbers, so "constant '3.0'" and "type 'double'").

It seems the static and runtime types gets mixed up somewhere along the way, to the point where we likely try to check that the constant value is a subtype of its static type. Any time we check actual values, we should use the extension-erased static type.

Metadata

Metadata

Assignees

Labels

cfe-feature-extension-typesImplement extension types feature in the CFEfeature-extension-typesImplementation of the extension type featurelegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions