You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to evaluate expressions with top level symbols like print or class names #18160
I recently implemented something called "log points" in Dart Code where we let the user provide an expression and we wrap it in print() and send it to the debugger via evaluateInFrame. At some point in the past, I'm certain this worked fine:
However today, this seems completely broken. I've tried various versions of Flutter and Dart Code and can't make the example in the screenshot work at all (I even went back several beta versions). However, the same thing seems to work fine in Dart VM scripts.
Here's what I get back from the VM in Flutter when trying to use print:
{"id": "400","method": "evaluateInFrame","params": {"expression": "print(\"\"\"_counter\"\"\")","frameIndex": 0,"isolateId": "isolates/909101337"}},{"jsonrpc": "2.0","result": {"type": "@Error","_vmType": "UnhandledException","kind": "UnhandledException","id": "objects\/1","message":"Unhandled exception:\nNoSuchMethodError: Class '_MyHomePageState' has no instance method 'print'.\nReceiver: Instance of '_MyHomePageState'\nTried calling: print(\"_counter\")\n..."}}
And here's what happens if I try to use a class name like DateTime:
Unhandled exception:\n'file:\/\/\/Users\/dantup\/Dev\/Dart-Code\/test\/test_projects\/flutter_hello_world\/lib\/main.dart':
malformed type: line 1pos9: cannotresolveclass'DateTime'from'MyHomePage'
As well as affecting log points, this happens from the Debug Console, so if the user types (new DateTime.now()).year into the Debug Console for a Dart CLI script it works fine, but in Flutter it fails. Using the Flutter version of the SDK for both tests.
I think this is a dart2 issue - when the CFE is enabled by default. /cc @aam, who's been working expression evaluation in dart2. Alex, is there any new guidance in using expr. eval w/ the CFE enabled?
Currently, in Flutter engine expressions are evaluated in dart1 mode by dart1-compilant parser that is built-in into engine's dart vm. With https://dart-review.googlesource.com/c/sdk/+/49061 and #16161 it will get switched to using flutter tools dart2 frontend for expression compilation.
Having said that, I am not sure what is the cause for errors above. Are you able to reproduce those failures if you use expression evaluation in observatory for Flutter app?
Since I have a screenshot showing this working from only a couple of weeks ago, if it's useful I could bisect this and find out which changesets work/fail if it's useful (it'll be a little bit manual, so I'm only gonna do it if you think it'd be useful).
Ah, I realized just now I was not going far enough back to find working version of Flutter. Turns out it got broken back in March with culprit being 71b2cfb
Weird, I must've somehow been on a really old version of Flutter when I coded this (which is possible, I do have many versions checked out from testing; but I hadn't deliberately been using them recently!).
Is switching the expression compilation to Dart 2 far off?
I can't reproduce any issues myself so have asked for more info, but thought I'd give you a heads up. I'll open a new issue and ping you on it if I can get a repro/log file.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
devoncarew commentedon Jun 4, 2018
I think this is a dart2 issue - when the CFE is enabled by default. /cc @aam, who's been working expression evaluation in dart2. Alex, is there any new guidance in using expr. eval w/ the CFE enabled?
aam commentedon Jun 4, 2018
Currently, in Flutter engine expressions are evaluated in dart1 mode by dart1-compilant parser that is built-in into engine's dart vm. With https://dart-review.googlesource.com/c/sdk/+/49061 and #16161 it will get switched to using flutter tools dart2 frontend for expression compilation.
Having said that, I am not sure what is the cause for errors above. Are you able to reproduce those failures if you use expression evaluation in observatory for Flutter app?
DanTup commentedon Jun 4, 2018
@aam Yep, same thing in Observatory web app:
(FWIW, I did try passing
--no-preview-dart-2toflutter runand indeed it had no effect.)DanTup commentedon Jun 4, 2018
Since I have a screenshot showing this working from only a couple of weeks ago, if it's useful I could bisect this and find out which changesets work/fail if it's useful (it'll be a little bit manual, so I'm only gonna do it if you think it'd be useful).
aam commentedon Jun 4, 2018
Yeah @DanTup , if you could let me know what revision of Flutter
p print(1)worked in observatory, that would help. Thanks!aam commentedon Jun 4, 2018
Ah, I realized just now I was not going far enough back to find working version of Flutter. Turns out it got broken back in March with culprit being 71b2cfb
aam commentedon Jun 4, 2018
This should get fixed with the switch to dart2 frontend for expression compilation mentioned above in #18160 (comment)
DanTup commentedon Jun 5, 2018
Weird, I must've somehow been on a really old version of Flutter when I coded this (which is possible, I do have many versions checked out from testing; but I hadn't deliberately been using them recently!).
Is switching the expression compilation to Dart 2 far off?
aam commentedon Jun 5, 2018
Hopefully it happens today
aam commentedon Jun 5, 2018
This should be fixed in f11c8d9.
DanTup commentedon Jun 6, 2018
LGTM, thanks! :)
DanTup commentedon Jun 18, 2018
@aam there's a report in flutter-dev of evaluation issues recently - I'm not sure if they may have been introduced with this change:
https://groups.google.com/forum/#!topic/flutter-dev/O-mTAk00hos
I can't reproduce any issues myself so have asked for more info, but thought I'd give you a heads up. I'll open a new issue and ping you on it if I can get a repro/log file.
aam commentedon Jun 18, 2018
thanks for the heads up @DanTup
Manual roll of engine 7e205b3...3953c3c
Manual roll of engine 7e205b3...3953c3c
Manual roll of engine 7e205b3...3953c3c (#56677)
github-actions commentedon Sep 3, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.