Skip to content

CFE accepts implicit invocation of .call getter via extension #45551

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

Open
stereotype441 opened this issue Apr 1, 2021 · 2 comments
Open

CFE accepts implicit invocation of .call getter via extension #45551

stereotype441 opened this issue Apr 1, 2021 · 2 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@stereotype441
Copy link
Member

stereotype441 commented Apr 1, 2021

The following code produces an error in the analyzer, but no error in the CFE:

class C {}
extension on C? {
  void Function() get call => () {}; // (1)
}
f(C? c) {
  c(); // ERROR: The expression doesn't evaluate to a function, so it can't be invoked.
}

I believe the CFE behavior is correct. c() should be considered equivalent to c.call(), and since call is a getter defined on type C?, it should be allowed. EDIT: analyzer behavior is correct - see Leaf's comment below.

Note that if line (1) is changed to void call() {} (which should be equivalent), then both the analyzer and CFE agree that there is no error.

@stereotype441 stereotype441 added the legacy-area-analyzer Use area-devexp instead. label Apr 1, 2021
dart-bot pushed a commit that referenced this issue Apr 1, 2021
These tests just cover the CFE functionality.  Once
#44905 is addressed, I'll add
test expectations for the analyzer.

Note: these tests uncovered two unreelated bugs: #45551 and #45552.

Bug: #44897
Change-Id: I465b157afc2cc15bcc5ce083aaa74614313a38a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193581
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Leaf Petersen <[email protected]>
Reviewed-by: Bob Nystrom <[email protected]>
@leafpetersen
Copy link
Member

I believe the analyzer behavior is correct here, and the CFE is missing an error. See sections 13.5 and 17.15.5 here.

@devoncarew devoncarew added legacy-area-front-end Legacy: Use area-dart-model instead. and removed legacy-area-analyzer Use area-devexp instead. labels Apr 1, 2021
@stereotype441
Copy link
Member Author

@leafpetersen oops, you are right. Here's the relevant text from section 13.5 (The call Member of an Extension) of the spec:

In particular, i' cannot be an invocation of an extension getter whose return type is a function type, Function, or dynamic.

@stereotype441 stereotype441 changed the title Analyzer fails to resolve implicit .call getter on nullable type via extension CFE accepts implicit invocation of .call getter via extension Apr 1, 2021
dart-bot pushed a commit that referenced this issue Apr 6, 2021
Previously, the "why not promoted" test cases sort of exercised this
bug, but in an unclear way that wasn't really related to the "why not
promoted" functionality.  Better to have a separate test for it.

Bug: #45551
Change-Id: Idd44596f021eb91679a019f9f56da1661363d0d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193829
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
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.
Projects
None yet
Development

No branches or pull requests

3 participants