Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: pkg/analyzer/test/generated/static_type_warning_code_test.dart

Issue 1910033002: Add warnings when async and async* functions declare a subtype of Future or Stream respectively (is… (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/static_type_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index 64bebe384b455e8853998314a9da960eb49cf339..4568fe9a1c8bc2651e920e8cc2c8f5de1f8f40d9 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -470,26 +470,26 @@ f() {
''');
}
- void test_illegal_return_type_async_function() {
+ void test_illegalAsyncGeneratorReturnType_function_nonStream() {
assertErrorsInCode(
'''
-int f() async {}
+int f() async* {}
''',
- [
- StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
- HintCode.MISSING_RETURN
- ]);
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
}
- void test_illegal_return_type_async_generator_function() {
+ void test_illegalAsyncGeneratorReturnType_function_subtypeOfStream() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
assertErrorsInCode(
'''
-int f() async* {}
+import 'dart:async';
+abstract class SubStream<T> implements Stream<T> {}
+SubStream<int> f() async* {}
''',
[StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
}
- void test_illegal_return_type_async_generator_method() {
+ void test_illegalAsyncGeneratorReturnType_method_nonStream() {
assertErrorsInCode(
'''
class C {
@@ -499,11 +499,48 @@ class C {
[StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
}
- void test_illegal_return_type_async_method() {
+ void test_illegalAsyncGeneratorReturnType_method_subtypeOfStream() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
+ assertErrorsInCode(
+ '''
+import 'dart:async';
+abstract class SubStream<T> implements Stream<T> {}
+class C {
+ SubStream<int> f() async* {}
+}
+''',
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE]);
+ }
+
+ void test_illegalAsyncReturnType_function_nonFuture() {
+ assertErrorsInCode(
+ '''
+int f() async {}
+''',
+ [
+ StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE,
+ HintCode.MISSING_RETURN
+ ]);
+ }
+
+ void test_illegalAsyncReturnType_function_subtypeOfFuture() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
+ assertErrorsInCode(
+ '''
+import 'dart:async';
+abstract class SubFuture<T> implements Future<T> {}
+SubFuture<int> f() async {
+ return 0;
+}
+''',
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]);
+ }
+
+ void test_illegalAsyncReturnType_method_nonFuture() {
assertErrorsInCode(
'''
class C {
- int f() async {}
+ int m() async {}
}
''',
[
@@ -512,7 +549,22 @@ class C {
]);
}
- void test_illegal_return_type_sync_generator_function() {
+ void test_illegalAsyncReturnType_method_subtypeOfFuture() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
+ assertErrorsInCode(
+ '''
+import 'dart:async';
+abstract class SubFuture<T> implements Future<T> {}
+class C {
+ SubFuture<int> m() async {
+ return 0;
+ }
+}
+''',
+ [StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE]);
+ }
+
+ void test_illegalSyncGeneratorReturnType_function_nonIterator() {
assertErrorsInCode(
'''
int f() sync* {}
@@ -520,7 +572,17 @@ int f() sync* {}
[StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
}
- void test_illegal_return_type_sync_generator_method() {
+ void test_illegalSyncGeneratorReturnType_function_subclassOfIterator() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
+ assertErrorsInCode(
+ '''
+abstract class SubIterator<T> implements Iterator<T> {}
+SubIterator<int> f() sync* {}
+''',
+ [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
+ }
+
+ void test_illegalSyncGeneratorReturnType_method_nonIterator() {
assertErrorsInCode(
'''
class C {
@@ -530,6 +592,18 @@ class C {
[StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
}
+ void test_illegalSyncGeneratorReturnType_method_subclassOfIterator() {
+ resetWithOptions(new AnalysisOptionsImpl()..strongMode = true);
+ assertErrorsInCode(
+ '''
+abstract class SubIterator<T> implements Iterator<T> {}
+class C {
+ SubIterator<int> f() sync* {}
+}
+''',
+ [StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE]);
+ }
+
void test_inconsistentMethodInheritance_paramCount() {
assertErrorsInCode(
r'''
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698