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

Incorrectly eliminated cast on numeric type in generic method #35618

munificent opened this Issue Jan 9, 2019 · 2 comments


None yet
2 participants
Copy link

munificent commented Jan 9, 2019

If I run this program:

T sum<T extends num>(T value) {
  return 0 as T;

void main() {
  double d;

On the bleeding edge VM:

Dart VM version: 2.2.0-edge.13a689f0fdb8de75f64db488d361edadae578d12 (Tue Jan 8 23:56:23 2019 +0000) on "macos_x64"

I get:

Unhandled exception:
type 'int' is not a subtype of type 'double' in type cast
#0      sum (file:///Users/rnystrom/temp/temp.dart:2:12)
#1      main (file:///Users/rnystrom/temp/temp.dart:8:9)
#2      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
#3      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

Note the first zero. The first call to sum() succeeds even though that cast should certainly fail. Interestingly, the call to isNaN apparently causes the cast inside the body of the function to be performed. I'm assuming some optimization pass is incorrectly eliminating the cast in the first call.


This comment has been minimized.

Copy link

mraleph commented Jan 10, 2019

This is a CFE bug:

 library from "file:///tmp/x.dart" as x {
   static method sum<T extends core::num = core::num>(x::sum::T value) → x::sum::T {
     return 0 as x::sum::T;
   static method main() → void {
     core::double d;

@mraleph mraleph added area-front-end and removed area-vm labels Jan 10, 2019


This comment has been minimized.

Copy link

munificent commented Jan 10, 2019

Thanks, I wasn't sure where the in pipeline the bug happened, so I randomly picked "area-vm". :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment