Skip to content

Type inference error in NNBD SDK #40492

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
liamappelbe opened this issue Feb 6, 2020 · 2 comments
Closed

Type inference error in NNBD SDK #40492

liamappelbe opened this issue Feb 6, 2020 · 2 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked

Comments

@liamappelbe
Copy link
Contributor

I'm hitting a type inference error in when I run some tests with the NNBD SDK. Minimal example:

import 'dart:async';

var events = [];

foo() async {
  return 'in async function';
}

void main() {
  var asyncValueFuture = foo().then(events.add);
  Future.wait(<Future>[asyncValueFuture]).then((_) {
    print(events);
  });
}

This outputs "[in async function]" on the old SDK, but in the NNBD SDK it gives this error:

Unhandled exception:
type '(Object) => void' is not a subtype of type '(dynamic) => FutureOr<dynamic>' of 'f'
#0      main (file:///usr/local/google/home/liama/dart-sdk/junk/future_bug.dart:10:32)
#1      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:167:12)

I can work around it by wrapping events.add in a lambda: (x) => events.add(x)

@a-siva fixed a similar issue in the libs by specifying the arg type in the lambda, and thinks it's a type inference bug in the CFE.

@liamappelbe liamappelbe added legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked labels Feb 6, 2020
@johnniwinther
Copy link
Member

Like caused by the missing normalization as with #40454

@johnniwinther
Copy link
Member

This seems to have been fixed by https://dart-review.googlesource.com/c/sdk/+/134842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked
Projects
None yet
Development

No branches or pull requests

2 participants