Issue 52486. Fix LinterContext.resolveNameInScope() in SwitchExpression cases.
Bug: https://github.com/dart-lang/sdk/issues/52486 Change-Id: I7d00ed03f8da37e7adb2959a62acefbd1904770a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305060 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
committed by
Commit Queue
parent
0fae0f373a
commit
645587bc70
@@ -1,3 +1,7 @@
|
||||
## 5.14.0-dev
|
||||
* Updated SDK constraint to `>=3.0.0 <4.0.0`.
|
||||
* Fixed #52486.
|
||||
|
||||
## 5.13.0
|
||||
* `InvalidType` is now used when types or property cannot be resolved.
|
||||
Previously `DynamicType` was used.
|
||||
|
||||
@@ -4961,6 +4961,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
|
||||
|
||||
for (var case_ in node.cases) {
|
||||
_withNameScope(() {
|
||||
_setNodeNameScope(case_, nameScope);
|
||||
var guardedPattern = case_.guardedPattern;
|
||||
var variables = guardedPattern.variables;
|
||||
for (var variable in variables.values) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: analyzer
|
||||
version: 5.13.0
|
||||
version: 5.14.0-dev
|
||||
description: >-
|
||||
This package provides a library that performs static analysis of Dart code.
|
||||
repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer
|
||||
|
||||
@@ -414,6 +414,59 @@ class A {
|
||||
_checkMethodRequestedLocalVariable();
|
||||
}
|
||||
|
||||
test_class_method_requested_patternVariable_ifCase() async {
|
||||
await resolve('''
|
||||
class A {
|
||||
void foo() {}
|
||||
|
||||
void bar(Object? x) {
|
||||
if (x case A(:var foo)) {
|
||||
this.foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
''', [
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 73, 3),
|
||||
]);
|
||||
_checkMethodRequestedLocalVariable();
|
||||
}
|
||||
|
||||
test_class_method_requested_patternVariable_switchExpression() async {
|
||||
await resolve('''
|
||||
class A {
|
||||
void foo() {}
|
||||
|
||||
void bar(Object? x) {
|
||||
(switch (x) {
|
||||
A(:var foo) => this.foo(),
|
||||
_ => 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
''', [
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 82, 3),
|
||||
]);
|
||||
_checkMethodRequestedLocalVariable();
|
||||
}
|
||||
|
||||
test_class_method_requested_patternVariable_switchStatement() async {
|
||||
await resolve('''
|
||||
class A {
|
||||
void foo() {}
|
||||
|
||||
void bar(Object? x) {
|
||||
switch (x) {
|
||||
case A(:var foo):
|
||||
this.foo();
|
||||
}
|
||||
}
|
||||
}
|
||||
''', [
|
||||
error(WarningCode.UNUSED_LOCAL_VARIABLE, 86, 3),
|
||||
]);
|
||||
_checkMethodRequestedLocalVariable();
|
||||
}
|
||||
|
||||
test_class_method_requested_thisClass() async {
|
||||
await resolve('''
|
||||
class A {
|
||||
|
||||
Reference in New Issue
Block a user