Skip to content

CFE doesn't allow implicit cast from dynamic in async function under NNBD #42282

Closed
@munificent

Description

@munificent

Consider:

import 'dart:async';

Future<int> foo() async {
  dynamic x = 123;
  return x;
}

main() {
  foo();
}

This program runs fine normally, but if I run:

$ dart --enable-experiment=non-nullable temp.dart

Then I get:

temp.dart:9:10: Error: A value of type 'Future<dynamic>' can't be assigned to a variable of type 'FutureOr<int>'.
 - 'Future' is from 'dart:async'.
 - 'FutureOr' is from 'dart:async'.
  return x;
         ^

From talking to @eernst, my understanding is that this code should continue to be allowed under null safety.

Metadata

Metadata

Assignees

No one assigned

    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