Skip to content

Explicit extension invocation allows null-aware member access #39325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sgrekhov opened this issue Nov 11, 2019 · 5 comments
Closed

Explicit extension invocation allows null-aware member access #39325

sgrekhov opened this issue Nov 11, 2019 · 5 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

According to the Static Extension specification

It is a compile-time error if an extension application occurs in a place where it is not the target expression of a simple or composite member invocation. That is, the only valid use of an extension application is to invoke members on it. This is similar to how prefix names can also only be used as member invocation targets. The main difference is that extensions can also declare operators. This also includes null-aware member access like E(o)?.id or E(o)?.[v] because those need to evaluate the target to a value and extension applications cannot evaluate to a value.

In fact, there are no compile-time errors to use null-aware member access on explicit extensions

class C {
}

extension Ext on C {
  int id() => 42;
}

main() {
  C c = C();
  Ext(c)?.id();
}

The code above produces no issues in analyzer and no errors at runtime

dartanalyzer version 2.7.0-dev.0.0
Dart VM version: 2.7.0-dev.0.0 (Tue Nov 5 12:57:33 2019 +0100) on "windows_x64"

@sgrekhov
Copy link
Contributor Author

See also #39326

@lrhn lrhn added legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P1 A high priority bug; for example, a single project is unusable or has many test failures labels Nov 11, 2019
@lrhn lrhn added this to the D27 Release milestone Nov 11, 2019
@vsmenon
Copy link
Member

vsmenon commented Nov 12, 2019

@leafpetersen @stereotype441 @johnniwinther - is this a change we need for D27? Spec / analyzer / CFE / all?

@vsmenon
Copy link
Member

vsmenon commented Nov 12, 2019

Also see #39326

@vsmenon vsmenon removed this from the D27 Release milestone Nov 12, 2019
@vsmenon
Copy link
Member

vsmenon commented Nov 12, 2019

We decided this should not block the D27 release.

@leafpetersen
Copy link
Member

We've decided to change the spec to allow this, so there is no front end or analyzer work required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants