-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.vm-nnbd-unfork-sdkLabel for all issues that need to be done before the nnbd sdk can be unforkedLabel for all issues that need to be done before the nnbd sdk can be unforked
Description
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.
Metadata
Metadata
Assignees
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.vm-nnbd-unfork-sdkLabel for all issues that need to be done before the nnbd sdk can be unforkedLabel for all issues that need to be done before the nnbd sdk can be unforked