Skip to content

Wrong behaviour for explicit extension invocation in form E(o)?.[v] #39326

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

Wrong behaviour for explicit extension invocation in form E(o)?.[v] #39326

sgrekhov opened this issue Nov 11, 2019 · 5 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

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,

class C {
}

extension Ext on C {
  int operator [](int index) => index;
}

main() {
  C c = C();
  Ext(c)?.[42];
}

No error at runtime. In analyzer

dartanalyzer --enable-experiment=extension-methods explicit_extension_member_invocation_A20_t04.dart
Analyzing explicit_extension_member_invocation_A20_t04.dart...
  error - The getter '[' isn't defined for the extension 'Ext'. - explicit_extension_member_invocation_A20_t04.dart:32:11 - undefined_extension_getter
  error - Expected an identifier. - explicit_extension_member_invocation_A20_t04.dart:32:11 - missing_identifier
2 errors found.

These error messages are wrong. See also #39325

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"

@lrhn
Copy link
Member

lrhn commented Nov 11, 2019

The syntax ?. is not available in current Dart. It's expected to be introduced with NNBD.
It does look like a (conditional) member invocation, so it could be allowed, but it likely won't.

When NNBD happens, extension on types will be either nullable or not, so there won't be a need for a null-aware extension member invocation. The extension application itself won't be considered nullable, so it won't allow a ?..

@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) labels Nov 11, 2019
@sgrekhov
Copy link
Contributor Author

With non-nullable experimental flag there are no any errors in analyzer. But there must be according to the spec

@lrhn lrhn added this to the D27 Release milestone Nov 11, 2019
@jensjoha jensjoha assigned johnniwinther and unassigned jensjoha Nov 11, 2019
@johnniwinther johnniwinther modified the milestone: D27 Release Nov 11, 2019
@vsmenon vsmenon removed this from the D27 Release milestone Nov 12, 2019
@vsmenon
Copy link
Member

vsmenon commented Nov 12, 2019

We don't think this a blocker - this should only be an issue if nnbd is enabled, right?

@johnniwinther
Copy link
Member

Right.

@johnniwinther johnniwinther added the NNBD Issues related to NNBD Release label Jan 10, 2020
@johnniwinther johnniwinther added this to the D29 Release milestone Jan 10, 2020
@franklinyow franklinyow modified the milestones: D29 Release, D28 Release Jan 21, 2020
@johnniwinther
Copy link
Member

Null aware access is now allowed. No work required for the CFE.

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. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants