Skip to content

NNBD: Analyzer throws a compile error when async function returns dynamic #41266

Closed
@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 fails with analyzer on the line 3 and passes with dart:

dynamic getNull() => null;

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

main() {}

Seems like there should not be compile error here.

Please note that analyzer is OK with the lines 4 and 5.

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

    legacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions