mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
[analyzer] UNUSED_RESULT
to handle PrefixExpression
Fixes #49975 Change-Id: I30d08994b214b5bb453b45ca4ef98c45cebc22a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259589 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
065b7d6d62
commit
f92aaae20c
|
@ -199,6 +199,7 @@ class UseResultVerifier {
|
|||
parent is ForElement ||
|
||||
parent is IfElement ||
|
||||
parent is ParenthesizedExpression ||
|
||||
parent is PrefixExpression ||
|
||||
parent is SpreadElement) {
|
||||
return _isUsed(parent);
|
||||
}
|
||||
|
|
|
@ -1168,6 +1168,71 @@ const a = 'a';
|
|||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_prefixExpression_bang() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@useResult
|
||||
bool foo() => true;
|
||||
|
||||
bool f() {
|
||||
return !foo();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_prefixExpression_decrement() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@useResult
|
||||
int foo = 1;
|
||||
|
||||
int f() {
|
||||
return --foo;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_prefixExpression_increment() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@useResult
|
||||
int foo = 1;
|
||||
|
||||
int f() {
|
||||
return ++foo;
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_prefixExpression_minus() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@useResult
|
||||
int foo() => 1;
|
||||
|
||||
int f() {
|
||||
return -foo();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_prefixExpression_tilde() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
@useResult
|
||||
int foo() => 1;
|
||||
|
||||
int f() {
|
||||
return ~foo();
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
test_topLevelFunction_result_assigned() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
import 'package:meta/meta.dart';
|
||||
|
|
Loading…
Reference in a new issue