Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bebc7d3

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer: Add a failing test for #38188
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>
1 parent 76e3faa commit bebc7d3

File tree

3 files changed

+76
-46
lines changed

3 files changed

+76
-46
lines changed

pkg/analyzer/test/generated/static_type_warning_code_test.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -435,52 +435,6 @@ class C {
435435
]);
436436
}
437437

438-
test_illegalAsyncReturnType_function_nonFuture() async {
439-
await assertErrorsInCode('''
440-
int f() async {}
441-
''', [
442-
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
443-
error(HintCode.MISSING_RETURN, 4, 1),
444-
]);
445-
}
446-
447-
test_illegalAsyncReturnType_function_subtypeOfFuture() async {
448-
await assertErrorsInCode('''
449-
import 'dart:async';
450-
abstract class SubFuture<T> implements Future<T> {}
451-
SubFuture<int> f() async {
452-
return 0;
453-
}
454-
''', [
455-
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 73, 14),
456-
]);
457-
}
458-
459-
test_illegalAsyncReturnType_method_nonFuture() async {
460-
await assertErrorsInCode('''
461-
class C {
462-
int m() async {}
463-
}
464-
''', [
465-
error(HintCode.MISSING_RETURN, 16, 1),
466-
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 12, 3),
467-
]);
468-
}
469-
470-
test_illegalAsyncReturnType_method_subtypeOfFuture() async {
471-
await assertErrorsInCode('''
472-
import 'dart:async';
473-
abstract class SubFuture<T> implements Future<T> {}
474-
class C {
475-
SubFuture<int> m() async {
476-
return 0;
477-
}
478-
}
479-
''', [
480-
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 85, 14),
481-
]);
482-
}
483-
484438
test_illegalSyncGeneratorReturnType_function_nonIterator() async {
485439
await assertErrorsInCode('''
486440
int f() sync* {}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/driver_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(IllegalAsyncReturnTypeTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class IllegalAsyncReturnTypeTest extends DriverResolutionTest {
18+
test_function_nonFuture() async {
19+
await assertErrorsInCode('''
20+
int f() async {}
21+
''', [
22+
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
23+
error(HintCode.MISSING_RETURN, 4, 1),
24+
]);
25+
}
26+
27+
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/38188')
28+
test_function_nonFuture_withReturn() async {
29+
await assertErrorsInCode('''
30+
int f() async {
31+
return 2;
32+
}
33+
''', [
34+
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 0, 3),
35+
]);
36+
}
37+
38+
test_function_subtypeOfFuture() async {
39+
await assertErrorsInCode('''
40+
import 'dart:async';
41+
abstract class SubFuture<T> implements Future<T> {}
42+
SubFuture<int> f() async {
43+
return 0;
44+
}
45+
''', [
46+
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 73, 14),
47+
]);
48+
}
49+
50+
test_method_nonFuture() async {
51+
await assertErrorsInCode('''
52+
class C {
53+
int m() async {}
54+
}
55+
''', [
56+
error(HintCode.MISSING_RETURN, 16, 1),
57+
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 12, 3),
58+
]);
59+
}
60+
61+
test_method_subtypeOfFuture() async {
62+
await assertErrorsInCode('''
63+
import 'dart:async';
64+
abstract class SubFuture<T> implements Future<T> {}
65+
class C {
66+
SubFuture<int> m() async {
67+
return 0;
68+
}
69+
}
70+
''', [
71+
error(StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, 85, 14),
72+
]);
73+
}
74+
}

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ import 'for_in_with_const_variable_test.dart' as for_in_with_const_variable;
139139
import 'generic_struct_subclass_test.dart' as generic_struct_subclass;
140140
import 'if_element_condition_from_deferred_library_test.dart'
141141
as if_element_condition_from_deferred_library;
142+
import 'illegal_async_return_type_test.dart' as illegal_async_return_type;
142143
import 'implements_disallowed_class_test.dart' as implements_disallowed_class;
143144
import 'implements_non_class_test.dart' as implements_non_class;
144145
import 'implements_super_class_test.dart' as implements_super_class;
@@ -570,6 +571,7 @@ main() {
570571
for_in_with_const_variable.main();
571572
generic_struct_subclass.main();
572573
if_element_condition_from_deferred_library.main();
574+
illegal_async_return_type.main();
573575
implements_disallowed_class.main();
574576
implements_non_class.main();
575577
implements_super_class.main();

0 commit comments

Comments
 (0)