mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
Issue 52136. Report USE_OF_VOID_RESULT for SwitchExpression.
Bug: https://github.com/dart-lang/sdk/issues/52136 Change-Id: I3a3b8f45419c57deec77deae37cd5f98481debeb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298400 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
1d28f8e821
commit
c13acbf1dd
|
@ -1252,6 +1252,18 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSwitchExpression(SwitchExpression node) {
|
||||
checkForUseOfVoidResult(node.expression);
|
||||
super.visitSwitchExpression(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSwitchExpressionCase(SwitchExpressionCase node) {
|
||||
checkForUseOfVoidResult(node.expression);
|
||||
super.visitSwitchExpressionCase(node);
|
||||
}
|
||||
|
||||
@override
|
||||
void visitSwitchPatternCase(SwitchPatternCase node) {
|
||||
_withHiddenElements(node.statements, () {
|
||||
|
|
|
@ -213,6 +213,40 @@ void main() {
|
|||
]);
|
||||
}
|
||||
|
||||
test_switchExpression_expression() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(void x) {
|
||||
(switch(x) {
|
||||
_ => 0,
|
||||
});
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 27, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_switchExpressionCase_expression() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(Object? x) {
|
||||
(switch(x) {
|
||||
_ => print(x),
|
||||
});
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 44, 5),
|
||||
]);
|
||||
}
|
||||
|
||||
test_switchStatement_expression() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(void x) {
|
||||
switch(x) {}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_throwVoidValueError() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(void x) {
|
||||
|
@ -527,16 +561,6 @@ void main() {
|
|||
]);
|
||||
}
|
||||
|
||||
test_useOfVoidInSwitchExpressionError() async {
|
||||
await assertErrorsInCode('''
|
||||
void f(void x) {
|
||||
switch(x) {}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.USE_OF_VOID_RESULT, 26, 1),
|
||||
]);
|
||||
}
|
||||
|
||||
test_useOfVoidInWhileConditionError() async {
|
||||
await assertErrorsInCode('''
|
||||
void main() {
|
||||
|
|
Loading…
Reference in a new issue