Skip to content

Commit 8bf801f

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes pattern variable with multiple declarations highlight
Bug: #60398 Change-Id: Ifd7c29db38bb2ee048d2b7d0de1e050e1e3e9bc2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417964 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent a003351 commit 8bf801f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pkg/analysis_server/lib/src/domains/analysis/occurrences_dart.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ class DartUnitOccurrencesComputerVisitor extends RecursiveAstVisitor<void> {
100100

101101
@override
102102
void visitDeclaredVariablePattern(DeclaredVariablePattern node) {
103-
_addOccurrence(node.declaredElement2!, node.name);
103+
if (node.declaredElement2 case BindPatternVariableElement2(:var join2?)) {
104+
_addOccurrence(join2.baseElement, node.name);
105+
} else {
106+
_addOccurrence(node.declaredElement2!, node.name);
107+
}
104108

105109
super.visitDeclaredVariablePattern(node);
106110
}

pkg/analysis_server/test/analysis/notification_occurrences_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,18 @@ String f(int char) {
576576
''');
577577
}
578578

579+
Future<void> test_patternVariable_ifCase_logicalOr() async {
580+
await assertOccurrences(kind: ElementKind.LOCAL_VARIABLE, '''
581+
void f(Object? x) {
582+
if (x case int /*[0*/test/*0]*/ || [int /*[1*/test/*1]*/] when /*[2*/test/*2]*/ > 0) {
583+
/*[3*/test/*3]*/;
584+
/*[4*/test/*4]*/ = 1;
585+
/*[5*/test/*5]*/ += 2;
586+
}
587+
}
588+
''');
589+
}
590+
579591
Future<void> test_prefix() async {
580592
await assertOccurrences(kind: ElementKind.PREFIX, '''
581593
import '' as /*[0*/p/*0]*/;

0 commit comments

Comments
 (0)