Issue 38799. Test that function expressions can infer Never as return type.

R=brianwilkerson@google.com

Bug: https://github.com/dart-lang/sdk/issues/38799
Change-Id: I1093749cb31a00a1b450c23ec4631595bce4bd00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149605
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2020-06-01 18:38:07 +00:00 committed by commit-bot@chromium.org
parent 058e25875c
commit 197bc061b9

View file

@ -232,6 +232,27 @@ var v = () {
_assertReturnType('() {', 'int');
}
test_noContext_returnType_sync_blockBody_dynamic() async {
await resolveTestCode('''
var v = (dynamic a) {
return a;
};
''');
_assertReturnType('(dynamic a) {', 'dynamic');
}
test_noContext_returnType_sync_blockBody_Never() async {
await resolveTestCode('''
var v = () {
throw 42;
};
''');
_assertReturnType(
'() {',
typeStringByNullability(nullable: 'Never', legacy: 'Null'),
);
}
test_noContext_returnType_sync_blockBody_notNullable() async {
await resolveTestCode('''
var v = (bool b) {
@ -327,6 +348,13 @@ main() {
);
}
test_noContext_returnType_sync_expressionBody_dynamic() async {
await resolveTestCode('''
var v = (dynamic a) => a;
''');
_assertReturnType('(dynamic a) =>', 'dynamic');
}
test_noContext_returnType_sync_expressionBody_Never() async {
await resolveTestCode('''
var v = () => throw 42;