Skip to content

Extension type new syntax available in dart Dart 3.3.0-174.2.beta, some questions and thoughts #54293

Closed
@brilliapps

Description

@brilliapps

Normally i ask on the dart official discord server. Comments in the code are describing what is happening and why something else could happen in some cases, what i see, and what in my opinion (limited knowledge) would cause the "extension type" to be perfect.
Please take note that there is here below a new type Int defined, starting from a big letter I (not "int"). Also there may be similar situations like these below, but this is enough for now.

extension type Int(int i) implements int {
  Int operator +(int other) {
    return Int(i + other);
  }
}

void main() {
  int a = 2;
  Int b = Int(8); // coulndn't Int b = 8? and silently cast as Int?

  b = b + a; // wrong, but Int + operator overriden returns Int
  b = a + b; // wrong, because a is int, but couldn't it be silently cast to Int?
  a = a + b; // good as expected.
  print(b + a); // ok, somewhere toString is called for sure.
  print(b + b);
  print(a + b);
}

So, do you think that at least b = b + a shouldn't be marked as error in my VScode? I imagined a reason why it should, but i don't know. Any opinions?

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onfeature-extension-typesImplementation of the extension type featurelegacy-area-analyzerUse area-devexp 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