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

TypeError.toString() message has regressed for simple types #50756

Closed
jakemac53 opened this issue Dec 16, 2022 · 5 comments
Closed

TypeError.toString() message has regressed for simple types #50756

jakemac53 opened this issue Dec 16, 2022 · 5 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jakemac53
Copy link
Contributor

jakemac53 commented Dec 16, 2022

Consider the following test, which would have passed in older SDKs.

import 'package:test/test.dart';

void main() {
  test('TypeError "null as String" text does not mention type parameters', () {
    try {
      var x = null as String;
      print(x);
    } on TypeError catch (e) {
      expect(e.toString(),
          "type 'Null' is not a subtype of type 'String' in type cast'');
    }
  });
}

This now fails as follows:

Expected: 'type \'Null\' is not a subtype of type \'String\' in type cast\''
Actual: 'type \'Null\' is not a subtype of type \'String\' of \' in type cast\''

It looks like it is maybe trying to list some information about generic type parameters now, but String has no generic type parameters.

cc @lrhn

@jakemac53 jakemac53 added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Dec 16, 2022
@jakemac53
Copy link
Contributor Author

Note that in general I am not opposed to this message changing, we do have a golden test which will get broken, but I don't consider the exact message to be a part of the API. But I do think the new message is a regression from the old.

@lrhn
Copy link
Member

lrhn commented Dec 16, 2022

This is probably a bug in the removal of CastError.
The message in a type cast, leading space and all, seems like it gets put into a place where something else is expected. Maybe the name of a variable being assigned to.
It's badly formatted and reads worse, so it's definitely not what we want to end up with.

Let's see if we can make sure it looks like before.

@lrhn lrhn added library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Dec 16, 2022
@kevmoo
Copy link
Member

kevmoo commented Dec 19, 2022

void main() {
  print(null as int);
}

Also the grammar is just...off...

Unhandled exception:
type 'Null' is not a subtype of type 'int' of ' in type cast'
#0      main (file:///Users/kevmoo/github/json_serializable.dart/checked_yaml/example/boo.dart:2:14)
#1      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#2      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)

the of ' bit just seems...like a bad string template being applied!

kevmoo added a commit to google/json_serializable.dart that referenced this issue Dec 19, 2022
kevmoo added a commit to google/json_serializable.dart that referenced this issue Dec 19, 2022
@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. and removed area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Feb 9, 2023
@lrhn
Copy link
Member

lrhn commented Feb 9, 2023

The call to create this message seems to happen somewhere in VM C++ code, so tagging as area-vm.

@a-siva
Copy link
Contributor

a-siva commented Feb 9, 2023

#50756 should fix that message. I believe this regressed when CastError was deprecated and replaced by 'TypeError'

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. library-core type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants