Skip to content
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

Frontend: Constant evaluation allows extension methods. #39146

Closed
lrhn opened this issue Oct 28, 2019 · 2 comments
Closed

Frontend: Constant evaluation allows extension methods. #39146

lrhn opened this issue Oct 28, 2019 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Oct 28, 2019

Example:

extension on Object {
  int operator~() => 42;
}

main() {
 const Object o = Object();
 const int x = ~o;
 print(x);
}

The front-end constant evaluator does not catch that we try to invoke an extension member here, but instead crashes. Backends report this crash, here the VM:

$ dart extbad.dart
Unhandled exception:
'file:///usr/local/google/home/lrn/dart/co/sdk/dev/extbad.dart': error: Invocation of _extension#0|~
#0      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#1      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)

The constant evaluator should not allow ~ to be used in constant expression except when invoking the instance member ~ of int.

The specification is being updated to specify this clearly, but it has always been the intention that user code invocations cannot occur in constant expressions.

@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Oct 28, 2019
@johnniwinther
Copy link
Member

@askeksa-google can you take a look at this?

@askeksa-google
Copy link

Fix in https://dart-review.googlesource.com/c/sdk/+/123247

Test case fails in the analyzer. Filed #39149 for the analyzer bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants