-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Analyzer: Report generators with void return types.
Fixes dart-lang/sdk#32192 This has been illegal for some time. This change updates the analyzer to match the behavior of CFE. Also move the relevant tests to diagnostics/ Change-Id: I4539aeb65708e2594c52288a6b4584ba7e5455e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153066 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
- Loading branch information
Showing
4 changed files
with
166 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
pkg/analyzer/test/src/diagnostics/illegal_async_generator_return_type_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2020, 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(IllegalAsyncGeneratorReturnTypeTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class IllegalAsyncGeneratorReturnTypeTest extends DriverResolutionTest { | ||
test_function_nonStream() async { | ||
await assertErrorsInCode(''' | ||
int f() async* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 0, 3), | ||
]); | ||
} | ||
|
||
test_function_stream() async { | ||
await assertNoErrorsInCode(''' | ||
Stream<void> f() async* {} | ||
'''); | ||
} | ||
|
||
test_function_subtypeOfStream() async { | ||
await assertErrorsInCode(''' | ||
import 'dart:async'; | ||
abstract class SubStream<T> implements Stream<T> {} | ||
SubStream<int> f() async* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 73, 14), | ||
]); | ||
} | ||
|
||
test_function_void() async { | ||
await assertErrorsInCode(''' | ||
void f() async* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 0, 4), | ||
]); | ||
} | ||
|
||
test_method_nonStream() async { | ||
await assertErrorsInCode(''' | ||
class C { | ||
int f() async* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 12, 3), | ||
]); | ||
} | ||
|
||
test_method_subtypeOfStream() async { | ||
await assertErrorsInCode(''' | ||
import 'dart:async'; | ||
abstract class SubStream<T> implements Stream<T> {} | ||
class C { | ||
SubStream<int> f() async* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 85, 14), | ||
]); | ||
} | ||
|
||
test_method_void() async { | ||
await assertErrorsInCode(''' | ||
class C { | ||
void f() async* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, 12, 4), | ||
]); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
pkg/analyzer/test/src/diagnostics/illegal_sync_generator_return_type_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2020, 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(IllegalSyncGeneratorReturnTypeTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class IllegalSyncGeneratorReturnTypeTest extends DriverResolutionTest { | ||
test_function_iterator() async { | ||
await assertNoErrorsInCode(''' | ||
Iterable<void> f() sync* {} | ||
'''); | ||
} | ||
|
||
test_function_nonIterator() async { | ||
await assertErrorsInCode(''' | ||
int f() sync* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 0, 3), | ||
]); | ||
} | ||
|
||
test_function_subclassOfIterator() async { | ||
await assertErrorsInCode(''' | ||
abstract class SubIterator<T> implements Iterator<T> {} | ||
SubIterator<int> f() sync* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 56, 16), | ||
]); | ||
} | ||
|
||
test_function_void() async { | ||
await assertErrorsInCode(''' | ||
void f() sync* {} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 0, 4), | ||
]); | ||
} | ||
|
||
test_method_nonIterator() async { | ||
await assertErrorsInCode(''' | ||
class C { | ||
int f() sync* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 12, 3), | ||
]); | ||
} | ||
|
||
test_method_subclassOfIterator() async { | ||
await assertErrorsInCode(''' | ||
abstract class SubIterator<T> implements Iterator<T> {} | ||
class C { | ||
SubIterator<int> f() sync* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 68, 16), | ||
]); | ||
} | ||
|
||
test_method_void() async { | ||
await assertErrorsInCode(''' | ||
class C { | ||
void f() sync* {} | ||
} | ||
''', [ | ||
error(StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, 12, 4), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters