Skip to content

Commit d8e02c4

Browse files
Merge pull request #84 from Workiva/fixed_cascade_references
FEA-2496: Fixed Cascade Indexing
2 parents e6ec7a2 + d533b6b commit d8e02c4

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

lib/src/scip_visitor.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ class ScipVisitor extends GeneralizingAstVisitor {
115115
// is a `CompoundAssignmentExpression`, we know this node is referring
116116
// to an assignment line. In that case, use the read/write element attached
117117
// to this node instead of the [node]'s element
118-
if (node.parent is CompoundAssignmentExpression) {
119-
final assignmentNode = node.parent as CompoundAssignmentExpression;
120-
element = assignmentNode.readElement ?? assignmentNode.writeElement;
118+
if (element == null) {
119+
final assignmentExpr =
120+
node.thisOrAncestorOfType<CompoundAssignmentExpression>();
121+
if (assignmentExpr == null) return;
122+
123+
element = assignmentExpr.readElement ?? assignmentExpr.writeElement;
121124
}
122125

123126
// When the identifier is a field, the analyzer creates synthetic getters/

snapshots/input/basic-project/lib/other.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import 'more.dart' deferred as more;
22

33
class Foo {
44
int _far;
5+
bool value;
6+
String value2;
7+
double value3;
58
Foo(this._far);
69
}
710

@@ -19,4 +22,12 @@ void main() {
1922
more.loadLibrary().then((_) => {
2023
Bar('a').someMethod.call()
2124
});
25+
26+
Foo()..value = false;
27+
28+
final someStr = 'someStr';
29+
Foo()
30+
..value = true
31+
..value2 = someStr
32+
..value3 = 2.15
2233
}

snapshots/output/basic-project/lib/other.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
// ^^^ reference scip-dart pub dart:core 2.18.0 dart:core/int.dart/int#
1111
// ^^^^ definition local 0
1212
// documentation ```dart
13+
bool value;
14+
// ^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/bool.dart/bool#
15+
// ^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value.
16+
// documentation ```dart
17+
String value2;
18+
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/string.dart/String#
19+
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value2.
20+
// documentation ```dart
21+
double value3;
22+
// ^^^^^^ reference scip-dart pub dart:core 2.18.0 dart:core/double.dart/double#
23+
// ^^^^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3.
24+
// documentation ```dart
1325
Foo(this._far);
1426
// ^^^ definition scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#<constructor>().
1527
// documentation ```dart
@@ -57,4 +69,21 @@
5769
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#
5870
// ^^^^^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Bar#someMethod().
5971
});
72+
73+
Foo()..value = false;
74+
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#
75+
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value.
76+
77+
final someStr = 'someStr';
78+
// ^^^^^^^ definition local 5
79+
// documentation ```dart
80+
Foo()
81+
// ^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#
82+
..value = true
83+
// ^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value.
84+
..value2 = someStr
85+
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value2.
86+
// ^^^^^^^ reference local 5
87+
..value3 = 2.15
88+
// ^^^^^^ reference scip-dart pub dart_test 1.0.0 lib/other.dart/Foo#value3.
6089
}

0 commit comments

Comments
 (0)