Skip to content

Object is accepted as FutureOr<T> which results in runtime TypeError #42340

Closed
@cubuspl42

Description

@cubuspl42
import 'dart:async';

void complete_<T>(Completer<T> completer, T value) {
  print(T); // prints "Object"
  completer.complete(value);
}

void main(List<String> arguments) {
  final completer = Completer<int>();

  // completer.complete("foo");
  // Compilation error:
  // error: The argument type 'String' can't be assigned to the parameter type 'FutureOr<int>'. (argument_type_not_assignable at [HelloWorldDart] bin/main.dart:11)

  complete_(completer, 'foo');
  // Compilation success (no issues)
  // Runtime error:
  // type 'String' is not a subtype of type 'FutureOr<int>' of 'value'
}
▶ dart --version
Dart VM version: 2.8.4 (stable) (Wed Jun 3 12:26:04 2020 +0200) on "macos_x64"

REPL

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-as-intendedClosed as the reported issue is expected behaviortype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions