Skip to content

errors thrown by constant evaluator are unreadable #33216

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
mraleph opened this issue May 23, 2018 · 8 comments
Closed

errors thrown by constant evaluator are unreadable #33216

mraleph opened this issue May 23, 2018 · 8 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on
Milestone

Comments

@mraleph
Copy link
Member

mraleph commented May 23, 2018

 class B {
   const B(int v);
 }

 const dynamic c = "";

 void foo([x = const B(c)]) { }

 void main() {
   foo();
 }

results in

$ out/ReleaseX64/dart --preview-dart-2 /tmp/error.dart
Unhandled exception:
'file:///tmp/error.dart': error: Not a constant expression:  is not an instance of Type: class 'int'
#0      main (file:///tmp/error.dart:11:3)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

Not that the top-most frame does not actually point to the location of the type error - it points to the invocation of foo within the main.

The type error itself is very different from how VM reports other similar type errors.

Other cases:

 class A {
   const A(int v);
 }

 class C {
   const C(int v);
 }

 class B extends C {
   const B._(v) : super(v);

   const B(v) : this._(v);
 }

 const dynamic c = "";

 void foo([x = const B(c)]) { }

 void main() {
   foo();
 }

produces unreadable (notice double "Unhandled exception" and no location information on frame #1)

$ out/ReleaseX64/dart --preview-dart-2 /tmp/error.dart
Unhandled exception:
Unhandled exception:
type 'String' is not a subtype of type 'int'
#0      new B._ (file:///tmp/error.dart:11:24)
#1      new B (file:///tmp/error.dart)
#2      main (file:///tmp/error.dart:21:3)
#3      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
error: error evaluating constant constructor
#0      main (file:///tmp/error.dart:21:3)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

while

class A {
   const A(int v);
 }

 class C {
   const C(int v);
 }

 class B extends C {
   const B._(v, {x: const C(c)}) : super(v);

   const B(v) : this._(v);
 }

 const dynamic c = "";

 void foo([x = const B(c)]) { }

 void main() {
   foo();
 }

produces

$ out/ReleaseX64/dart --preview-dart-2 /tmp/error.dart
Unhandled exception:
Unhandled exception:
'file:///tmp/error.dart': error: Not a constant expression:  is not an instance of Type: class 'int'
#0      new B (file:///tmp/error.dart)
#1      main (file:///tmp/error.dart:21:3)
#2      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#3      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
error: error evaluating constant constructor
#0      main (file:///tmp/error.dart:21:3)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P0 A serious issue requiring immediate resolution area-kernel labels May 23, 2018
@mraleph mraleph added this to the Dart2Stable milestone May 23, 2018
@mraleph
Copy link
Member Author

mraleph commented May 23, 2018

@kmillikin please select priority

@matanlurey
Copy link
Contributor

THank you @mraleph (and @kmillikin)!

@kmillikin kmillikin added P2 A bug or feature request we're likely to work on and removed P0 A serious issue requiring immediate resolution labels May 24, 2018
@kmillikin kmillikin assigned a-siva and unassigned kmillikin Jun 15, 2018
@kmillikin
Copy link

I don't think there's anything we need to put in Kernel for the VM to generate a better error. @a-siva can you reassign to someone on the VM team? (Also, consider whether this is in scope for Dart2Stable.)

If it turns out we need to change something in Kernel, let us know.

@jensjoha
Copy link
Contributor

jensjoha commented Jul 6, 2018

With https://dart-review.googlesource.com/c/sdk/+/63883 I get

Unhandled exception:
'[...]/issue_33216.dart': error: line 7 pos 24: Not a constant expression: Type 'String' is not a subtype of type 'int'
 void foo([x = const B(c)]) { }
                       ^

#0      main ([...]/issue_33216.dart:10:4)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

then

Unhandled exception:
Unhandled exception:
type 'String' is not a subtype of type 'int'
#0      new B._ ([...]/issue_33216.dart:10:25)
#1      new B ([...]/issue_33216.dart:12:22)
#2      main ([...]/issue_33216.dart:20:4)
#3      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#4      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
'[...]/issue_33216.dart': error: line 17 pos 22: error evaluating constant constructor
 void foo([x = const B(c)]) { }
                     ^

#0      main ([...]/issue_33216.dart:20:4)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

and finally

Unhandled exception:
Unhandled exception:
'[...]/issue_33216.dart': error: line 10 pos 29: Not a constant expression: Type 'String' is not a subtype of type 'int'
   const B._(v, {x: const C(c)}) : super(v);
                            ^

#0      new B ([...]/issue_33216.dart:12:22)
#1      main ([...]/issue_33216.dart:20:4)
#2      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#3      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
'[...]/issue_33216.dart': error: line 17 pos 22: error evaluating constant constructor
 void foo([x = const B(c)]) { }
                     ^

#0      main ([...]/issue_33216.dart:20:4)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

Stuff like

Unhandled exception:
Unhandled exception:

might not be great, but --no-preview-dart-2 --checked does that too.

dart-bot pushed a commit that referenced this issue Jul 9, 2018
Use positions already available in for instance AsExpressions,
also adds new offsets in the kernel format to
SuperInitializer and RedirectingInitializer.

Bug: #33216
Change-Id: I542967ddc6ec782e6513d62fce038a49239e1622
Reviewed-on: https://dart-review.googlesource.com/63883
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
@dgrove
Copy link
Contributor

dgrove commented Jul 9, 2018

After talking with @kevmoo:

  • Dart Analyzer messages are fine for these cases
  • Dart VM messages are not too bad (given @jensjoha 's report)

Moving to Dart 2.1

@dgrove dgrove modified the milestones: Dart2Stable, Dart2.1 Jul 9, 2018
@a-siva
Copy link
Contributor

a-siva commented Jul 9, 2018

The error messages reported by Dart VM after the changes made by @jensjoha are consistent with what was being generated by Dart 1.
I would close this and open a new enhancement issue with more details on generating consistent error messages across the different tools.

@dgrove
Copy link
Contributor

dgrove commented Oct 9, 2018

@a-siva any updates for 2.1?

@a-siva
Copy link
Contributor

a-siva commented Oct 11, 2018

See comment above, I believe this issue can be closed unless somebody disagrees with that.

@dgrove dgrove closed this as completed Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

6 participants