Skip to content

Unable to evaluate expressions with top level symbols like print or class names #18160

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
DanTup opened this issue Jun 4, 2018 · 14 comments
Closed

Comments

@DanTup
Copy link
Contributor

DanTup commented Jun 4, 2018

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:

logpoint

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 1 pos 9: cannot resolve class '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.

@devoncarew
Copy link
Member

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
Copy link
Member

aam commented 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
Copy link
Contributor Author

DanTup commented Jun 4, 2018

@aam Yep, same thing in Observatory web app:

$ p print(1)
Unhandled exception:
NoSuchMethodError: No top-level method 'print' declared.
Receiver: top-level
Tried calling: print(1)
#0      NoSuchMethodError._throwNew (dart:core/runtime/liberrors_patch.dart:203:5)
#1      Eval (evaluate:source:1:7)
#2      main (file:///Users/dantup/Dev/Dart-Code/test/test_projects/flutter_hello_world/lib/main.dart:3:10)
#3      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
$ p new DateTime.now()
Unhandled exception:
'file:///Users/dantup/Dev/Dart-Code/test/test_projects/flutter_hello_world/lib/main.dart': malformed type: line 1 pos 5: cannot resolve class 'DateTime' from '::'
import 'package:flutter/material.dart';
    ^


#0      _TypeError._throwNew (dart:core/runtime/liberrors_patch.dart:84:75)
#1      Eval (evaluate:source:1:11)
#2      main (file:///Users/dantup/Dev/Dart-Code/test/test_projects/flutter_hello_world/lib/main.dart:3:10)
#3      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

(FWIW, I did try passing --no-preview-dart-2 to flutter run and indeed it had no effect.)

@DanTup
Copy link
Contributor Author

DanTup commented 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
Copy link
Member

aam commented 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
Copy link
Member

aam commented 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
Copy link
Member

aam commented Jun 4, 2018

This should get fixed with the switch to dart2 frontend for expression compilation mentioned above in #18160 (comment)

@DanTup
Copy link
Contributor Author

DanTup commented Jun 5, 2018

Turns out it got broken back in March

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
Copy link
Member

aam commented Jun 5, 2018

Hopefully it happens today

@aam
Copy link
Member

aam commented Jun 5, 2018

This should be fixed in f11c8d9.

@DanTup
Copy link
Contributor Author

DanTup commented Jun 6, 2018

LGTM, thanks! :)

screen shot 2018-06-06 at 7 15 31 am

@DanTup DanTup closed this as completed Jun 6, 2018
@DanTup
Copy link
Contributor Author

DanTup commented 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
Copy link
Member

aam commented Jun 18, 2018

thanks for the heads up @DanTup

a-siva added a commit to a-siva/flutter that referenced this issue May 8, 2020
7e205b3 Roll src/fuchsia/sdk/mac from 1MVsE... to 4MCVP... (flutter#18217)
9193d8f Roll src/third_party/skia 0dc207f836da..a14084ba1b41 (3 commits) (flutter#18219)
403931f Add FlValue (flutter#18185)
46a6d96 [SkParagraph] Copy text height behavior to the Skia paragraph style (flutter#18178)
e7ee47d [web] Implement matrix parameter for linear gradient (flutter#18208)
28d9985 Reland again "Remove layer integral offset snapping flutter#17112" (flutter#18160)
5e361f5 Roll src/third_party/skia c66cd987f7c0..0dc207f836da (5 commits) (flutter#18212)
716dbf0 Refactor GLFW embedding to support headless mode (flutter#18205)
23cca32 Manual Roll of Dart 39e0e75fcf...ce62ad2e8b (flutter#18211)
15f72b8 Support EventChannel C++ plugin API for Linux/Windows (flutter#17015)
e5a7ca5 Handle leak of message handle when no engine present (flutter#18157)
d3bde19 add docs to platformviewios (and some drive-by changes) (flutter#17593)
b582d77 Roll src/third_party/skia 0066adefa97d..c66cd987f7c0 (4 commits) (flutter#18206)
5e7d6d0 Roll src/third_party/skia edea19858ccc..0066adefa97d (3 commits) (flutter#18203)
88b9d42 Remove the global engine entry timestamp (flutter#18182)
0dffdd5 Roll src/third_party/dart e86e4d61834a..ce62ad2e8b40 (13 commits) (flutter#18201)
56fe6d2 Roll src/third_party/skia 2871ab0727bf..edea19858ccc (3 commits) (flutter#18198)
bcdf991 Fixed ChildSceneLayer elevation issue on Fuchsia. (flutter#18144)
ede658e [profiling] CPU Profiling support for iOS (flutter#18087)
d043923 Roll src/third_party/skia e3d1de7c5281..2871ab0727bf (1 commits) (flutter#18197)
807f191 Roll src/third_party/dart 733153eb517c..e86e4d61834a (6 commits) (flutter#18195)
fe3f8df Roll src/third_party/skia 3b2db26c59d6..e3d1de7c5281 (4 commits) (flutter#18192)
34b0629 Roll fuchsia/sdk/core/mac-amd64 from jMJqf... to 1MVsE... (flutter#18194)
e9b2afe Roll fuchsia/sdk/core/linux-amd64 from RpHTv... to MhpFP... (flutter#18191)
35fa006 Roll src/third_party/skia 88d04cb51acf..3b2db26c59d6 (1 commits) (flutter#18190)
e54bb9e Roll src/third_party/dart 4da5b40fb6dc..733153eb517c (23 commits) (flutter#18188)
a-siva added a commit to a-siva/flutter that referenced this issue May 8, 2020
7e205b3 Roll src/fuchsia/sdk/mac from 1MVsE... to 4MCVP... (flutter#18217)
9193d8f Roll src/third_party/skia 0dc207f836da..a14084ba1b41 (3 commits) (flutter#18219)
403931f Add FlValue (flutter#18185)
46a6d96 [SkParagraph] Copy text height behavior to the Skia paragraph style (flutter#18178)
e7ee47d [web] Implement matrix parameter for linear gradient (flutter#18208)
28d9985 Reland again "Remove layer integral offset snapping flutter#17112" (flutter#18160)
5e361f5 Roll src/third_party/skia c66cd987f7c0..0dc207f836da (5 commits) (flutter#18212)
716dbf0 Refactor GLFW embedding to support headless mode (flutter#18205)
23cca32 Manual Roll of Dart 39e0e75fcf...ce62ad2e8b (flutter#18211)
15f72b8 Support EventChannel C++ plugin API for Linux/Windows (flutter#17015)
e5a7ca5 Handle leak of message handle when no engine present (flutter#18157)
d3bde19 add docs to platformviewios (and some drive-by changes) (flutter#17593)
b582d77 Roll src/third_party/skia 0066adefa97d..c66cd987f7c0 (4 commits) (flutter#18206)
5e7d6d0 Roll src/third_party/skia edea19858ccc..0066adefa97d (3 commits) (flutter#18203)
88b9d42 Remove the global engine entry timestamp (flutter#18182)
0dffdd5 Roll src/third_party/dart e86e4d61834a..ce62ad2e8b40 (13 commits) (flutter#18201)
56fe6d2 Roll src/third_party/skia 2871ab0727bf..edea19858ccc (3 commits) (flutter#18198)
bcdf991 Fixed ChildSceneLayer elevation issue on Fuchsia. (flutter#18144)
ede658e [profiling] CPU Profiling support for iOS (flutter#18087)
d043923 Roll src/third_party/skia e3d1de7c5281..2871ab0727bf (1 commits) (flutter#18197)
807f191 Roll src/third_party/dart 733153eb517c..e86e4d61834a (6 commits) (flutter#18195)
fe3f8df Roll src/third_party/skia 3b2db26c59d6..e3d1de7c5281 (4 commits) (flutter#18192)
34b0629 Roll fuchsia/sdk/core/mac-amd64 from jMJqf... to 1MVsE... (flutter#18194)
e9b2afe Roll fuchsia/sdk/core/linux-amd64 from RpHTv... to MhpFP... (flutter#18191)
35fa006 Roll src/third_party/skia 88d04cb51acf..3b2db26c59d6 (1 commits) (flutter#18190)
e54bb9e Roll src/third_party/dart 4da5b40fb6dc..733153eb517c (23 commits) (flutter#18188)
a-siva added a commit that referenced this issue May 8, 2020
7e205b3 Roll src/fuchsia/sdk/mac from 1MVsE... to 4MCVP... (#18217)
9193d8f Roll src/third_party/skia 0dc207f836da..a14084ba1b41 (3 commits) (#18219)
403931f Add FlValue (#18185)
46a6d96 [SkParagraph] Copy text height behavior to the Skia paragraph style (#18178)
e7ee47d [web] Implement matrix parameter for linear gradient (#18208)
28d9985 Reland again "Remove layer integral offset snapping #17112" (#18160)
5e361f5 Roll src/third_party/skia c66cd987f7c0..0dc207f836da (5 commits) (#18212)
716dbf0 Refactor GLFW embedding to support headless mode (#18205)
23cca32 Manual Roll of Dart 39e0e75fcf...ce62ad2e8b (#18211)
15f72b8 Support EventChannel C++ plugin API for Linux/Windows (#17015)
e5a7ca5 Handle leak of message handle when no engine present (#18157)
d3bde19 add docs to platformviewios (and some drive-by changes) (#17593)
b582d77 Roll src/third_party/skia 0066adefa97d..c66cd987f7c0 (4 commits) (#18206)
5e7d6d0 Roll src/third_party/skia edea19858ccc..0066adefa97d (3 commits) (#18203)
88b9d42 Remove the global engine entry timestamp (#18182)
0dffdd5 Roll src/third_party/dart e86e4d61834a..ce62ad2e8b40 (13 commits) (#18201)
56fe6d2 Roll src/third_party/skia 2871ab0727bf..edea19858ccc (3 commits) (#18198)
bcdf991 Fixed ChildSceneLayer elevation issue on Fuchsia. (#18144)
ede658e [profiling] CPU Profiling support for iOS (#18087)
d043923 Roll src/third_party/skia e3d1de7c5281..2871ab0727bf (1 commits) (#18197)
807f191 Roll src/third_party/dart 733153eb517c..e86e4d61834a (6 commits) (#18195)
fe3f8df Roll src/third_party/skia 3b2db26c59d6..e3d1de7c5281 (4 commits) (#18192)
34b0629 Roll fuchsia/sdk/core/mac-amd64 from jMJqf... to 1MVsE... (#18194)
e9b2afe Roll fuchsia/sdk/core/linux-amd64 from RpHTv... to MhpFP... (#18191)
35fa006 Roll src/third_party/skia 88d04cb51acf..3b2db26c59d6 (1 commits) (#18190)
e54bb9e Roll src/third_party/dart 4da5b40fb6dc..733153eb517c (23 commits) (#18188)
@github-actions
Copy link

github-actions bot commented 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 -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants