Skip to content

Commit

Permalink
analyzer: Add a failing test for #38188
Browse files Browse the repository at this point in the history
Also move tests for illegal_async_return_type

Change-Id: Icd76c1ece456470ce734df2ac6628d5aedcd6e8e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Jan 4, 2020
1 parent 76e3faa commit bebc7d3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 46 deletions.
46 changes: 0 additions & 46 deletions pkg/analyzer/test/generated/static_type_warning_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -435,52 +435,6 @@ class C {
]);
}

test_illegalAsyncReturnType_function_nonFuture() async {
await assertErrorsInCode('''
int f() async {}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
error(HintCode.MISSING_RETURN, 4, 1),
]);
}

test_illegalAsyncReturnType_function_subtypeOfFuture() async {
await assertErrorsInCode('''
import 'dart:async';
abstract class SubFuture<T> implements Future<T> {}
SubFuture<int> f() async {
return 0;
}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 73, 14),
]);
}

test_illegalAsyncReturnType_method_nonFuture() async {
await assertErrorsInCode('''
class C {
int m() async {}
}
''', [
error(HintCode.MISSING_RETURN, 16, 1),
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 12, 3),
]);
}

test_illegalAsyncReturnType_method_subtypeOfFuture() async {
await assertErrorsInCode('''
import 'dart:async';
abstract class SubFuture<T> implements Future<T> {}
class C {
SubFuture<int> m() async {
return 0;
}
}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 85, 14),
]);
}

test_illegalSyncGeneratorReturnType_function_nonIterator() async {
await assertErrorsInCode('''
int f() sync* {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../dart/resolution/driver_resolution.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(IllegalAsyncReturnTypeTest);
});
}

@reflectiveTest
class IllegalAsyncReturnTypeTest extends DriverResolutionTest {
test_function_nonFuture() async {
await assertErrorsInCode('''
int f() async {}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
error(HintCode.MISSING_RETURN, 4, 1),
]);
}

@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38188')
test_function_nonFuture_withReturn() async {
await assertErrorsInCode('''
int f() async {
return 2;
}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
]);
}

test_function_subtypeOfFuture() async {
await assertErrorsInCode('''
import 'dart:async';
abstract class SubFuture<T> implements Future<T> {}
SubFuture<int> f() async {
return 0;
}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 73, 14),
]);
}

test_method_nonFuture() async {
await assertErrorsInCode('''
class C {
int m() async {}
}
''', [
error(HintCode.MISSING_RETURN, 16, 1),
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 12, 3),
]);
}

test_method_subtypeOfFuture() async {
await assertErrorsInCode('''
import 'dart:async';
abstract class SubFuture<T> implements Future<T> {}
class C {
SubFuture<int> m() async {
return 0;
}
}
''', [
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 85, 14),
]);
}
}
2 changes: 2 additions & 0 deletions pkg/analyzer/test/src/diagnostics/test_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import 'for_in_with_const_variable_test.dart' as for_in_with_const_variable;
import 'generic_struct_subclass_test.dart' as generic_struct_subclass;
import 'if_element_condition_from_deferred_library_test.dart'
as if_element_condition_from_deferred_library;
import 'illegal_async_return_type_test.dart' as illegal_async_return_type;
import 'implements_disallowed_class_test.dart' as implements_disallowed_class;
import 'implements_non_class_test.dart' as implements_non_class;
import 'implements_super_class_test.dart' as implements_super_class;
Expand Down Expand Up @@ -570,6 +571,7 @@ main() {
for_in_with_const_variable.main();
generic_struct_subclass.main();
if_element_condition_from_deferred_library.main();
illegal_async_return_type.main();
implements_disallowed_class.main();
implements_non_class.main();
implements_super_class.main();
Expand Down

0 comments on commit bebc7d3

Please sign in to comment.