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

Confusing type check error in VM in checked mode #2172

Closed
sethladd opened this issue Mar 14, 2012 · 8 comments
Closed

Confusing type check error in VM in checked mode #2172

sethladd opened this issue Mar 14, 2012 · 8 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@sethladd
Copy link
Contributor

This code:

import('dart:builtin');

add(String a, String b) {
  return a + b;
}

void main() {
  print(add(1, 2));
}

When run in the VM w/ checked mode, and via the Editor, generates this error:

Unhandled exception:
type 'Smi' is not a subtype of type 'String' of 'a'.
 0. Function: '::add' url: 'file:///Users/sethladd/dart/optionaltypes/optionaltypes.dart' line:3 col:12
 1. Function: '::main' url: 'file:///Users/sethladd/dart/optionaltypes/optionaltypes.dart' line:8 col:12

It is unclear and confusing what "Smi" is. It should read: "type 'int' is not a subtype of type 'String' of 'a'"

@ghost
Copy link

ghost commented Mar 14, 2012

What should be reported for following code?

#import('dart:coreimpl');

main() {
  Smi i = 1;
  String s = i;
}

or

Map x = new Map();
String s = x;

type 'HashMapImplementation<Dynamic, Dynamic>' is not a subtype of type 'String' of 's'.

While not always clear, the reported error is precise. A possible solution is to also print all implemented interfaces, but that can be quite verbose.

@sethladd
Copy link
Contributor Author

It is unclear what a Smi is. It's not in our docs.

@ghost
Copy link

ghost commented Mar 14, 2012

Maybe we should always print type 'num(Smi)', 'num(Mint)', 'num(BigInt)' when appropriate. Or fix docs?

@sethladd
Copy link
Contributor Author

We should avoid Smi, Mint, and BigInt, which are implementation details. Dart has num, int, and double. Frog correctly warns that "int is not of type String" in this case.

@ghost
Copy link

ghost commented Mar 15, 2012

Do not confuse static warnings with runtime checks! The later one look at the real type and throw an exception. They are enabled if running in checked mode.

Running frog in checked mode reports:
Failed type check: type Number is not assignable to type String

We can add one-offs for Smi, Mint, Bigint type error reporting, as those will be most likely to cause confusion.


Set owner to @sgmitrovic.
Added Accepted label.

@sethladd
Copy link
Contributor Author

Agreed, static warnings aren't runtime checks. However, I am concerned whenever we let implementation details bleed up to user facing messaging. Another example is when the VM talks about "GrowableArray" which is not in the spec nor in our api.dartlang.org docs. To the best of our efforts, we should hide implementation class names from user facing errors, or document these implementation names so users can track them down and not be surprised.

Thanks for your help with this!

@ghost
Copy link

ghost commented Mar 15, 2012

Fixed in r5525 (for integers).

There is now a central place in the VM where we map real type names to user-understandable names. Please continue reporting error usability issues. I do not add mapping too eagerly since these changes hide what type actually caused the error. We need to find a good balance.

The runtime checks know only about the real (implementation) type. E.g., in following code frog reports type "Array is not assignable to type num", while type "Array" is not documented (similar to the GrowableArray issue that you mentioned).

check(int a) { return a; }
void main() => check([1, 2]);

We need to have a consistent story across all Dart implementations.


Added Fixed label.

@sethladd
Copy link
Contributor Author

Thanks for the fix!

@sethladd sethladd added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Mar 15, 2012
@sethladd sethladd assigned ghost Mar 15, 2012
dart-bot pushed a commit that referenced this issue Oct 29, 2019
Includes the following commits:
80ac76400ff58fde3c5a335d860d196c3febe837 Warn about authors field in pubspec.yaml
6b6e02fcdd8094ccbba919b2fdc74947b1cebb71 Warn about old flutter plugin registration format (#2233)
8308acbc48ebd4da4ab7f45169af8dee4df18e79 Language versioning
b18d4f6a5d035f4f72ef187e9cdb133d18848c2d update doc
408bdd58ab01689fd82cc036b4142f7b592b4ba0 Added utility for faster local testing (#2235)
055fc19d2e06e819dbd47b3b56909c47bd893f66 Upgraded package:yaml to 2.2.0 (#2237)
0f3baf7abb13702f7fb1ff3709c584065df1435c Remove unused Map `availableVersions`
cfa9dc760b6b601f9473e65d15f15b60a319336d Fix to show proper error message when git is not installed (#2209)
d99b0d58f4059d7bb4ac4616fd3d54ec00a2b5d4 Rephrase warnings for missing deps (#2203)
76b8c30395b37f96d3db3e842344cc842bdd7c24 Don't mention 'transformed dependencies'. (#2199)
4bd65e0f54e6e4540f03467b0272a5666e8d54ba return the hashCode of the description (#2198)
92b52682e8fc6eed9ef2e77ed890647f75570165 Test more pre-release behavior. (#2175)
066ac118d406500f672339e25f0154af9321deac update to latest pkg:analyzer (#2172)
289804a5d2c9746b4e86c271c2abcfe17417e20f Minor typo fixed (#2166)

Change-Id: I3922bcaacb5399853a291b92d7192d21f719d224
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123404
Reviewed-by: Jonas Jensen <jonasfj@google.com>
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
This issue was closed.
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.
Projects
None yet
Development

No branches or pull requests

1 participant