diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index b97d45827d2..6c38466060f 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -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. diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart index 85940fa0390..bfd842f7cf5 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -4961,6 +4961,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { for (var case_ in node.cases) { _withNameScope(() { + _setNodeNameScope(case_, nameScope); var guardedPattern = case_.guardedPattern; var variables = guardedPattern.variables; for (var variable in variables.values) { diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml index e4bb774c374..76cad9776b1 100644 --- a/pkg/analyzer/pubspec.yaml +++ b/pkg/analyzer/pubspec.yaml @@ -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 diff --git a/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart b/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart index ecab45450ba..0b270003fee 100644 --- a/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart +++ b/pkg/analyzer/test/src/lint/linter/resolve_name_in_scope_test.dart @@ -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 {