Skip to content

Spurious NNBD error from CFE - Not inferring correct generic from argument context #41106

Closed
@natebosch

Description

@natebosch

Repro:

import 'dart:async';

void main() async {
  Completer<String>().complete(Future.value('hello'));
}

dartanalyzer --enable-experiment=non-nullable reports no errors.

Trying to run with dart --enable-experiment=non-nullable --null-safety fails:

try.dart:4:39: Error: The argument type 'Future<String?>' can't be assigned to the parameter type 'FutureOr<String>?'.
 - 'Future' is from 'dart:async'.
 - 'FutureOr' is from 'dart:async'.
  Completer<String>().complete(Future.value('hello'));
                                      ^

The workaround is to specify Future<String>.value(...)

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions