Skip to content

Representation variable of an extension type is not promoted #53446

@sgrekhov

Description

@sgrekhov

[Edit eernstg: See https://github.com/dart-lang/language/issues/3342 as well.]

According to the extension type specification representation variable is subject to promotion. But in the current implementation nor analyzer nor CFE don't promote it. For example, they both report errors below

// SharedOptions=--enable-experiment=inline-class

extension type ET1(int? id) {
  void test() {
    if (id != null) {
      id.isOdd; // Error
    }
  }
}

extension type ET2<T>(T id) {
  void test() {
    if (id is int) {
      id.isOdd; // Error
    }
  }
}

main() {
  ET1 et1 = ET1(1);
  if (et1.id != null) {
    et1.id.isEven; // Error
  }

  ET2<num?> et2 = ET2(2);
  if (et2.id != null) {
    et2.id.isEven;  // Error
  }
}

A separate issue for private fields promotion #53439

Tested on the edge SDK (Sept 6, 2023) on Linux x64

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work oncfe-feature-extension-typesImplement extension types feature in the CFEfeature-extension-typesImplementation of the extension type featurelegacy-area-analyzerUse area-devexp instead.legacy-area-front-endLegacy: Use area-dart-model instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions