Skip to content

NNBD: Dart does not throw a compile error when async function with Future<bool> return type returns dynamic. #41437

@iarkh

Description

@iarkh

Dart VM version: 2.8.0-dev.18.0 (dev) (Fri Mar 27 11:10:52 2020 +0100) on "windows_x64"

The following sample code example throws a compile error with analyzer on the line 3 and passes without any error with dart:

dynamic getNull() => null;

Future<bool> test1() async => await getNull();
Future<bool> test2() => getNull();
bool test3() => getNull();

main() {}

Seems like dart should throw a compile error here too. Please see discussion in the Issue #41266 for more details.

Sample output is:

$> dartanalyzer --enable-experiment=non-nullable test.dart
Analyzing test.dart...
error - A value of type 'dynamic' can't be returned from function 'test1' because it has a return type of 'bool'. - test.dart:3:31 - return_of_invalid_type
1 error found.

$> dart --enable-experiment=non-nullable test.dart
$

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