@@ -577,6 +577,46 @@ class B extends A {
577
577
);
578
578
}
579
579
580
+ Future <void > test_searchReferences_parameter_topLevelShadow_wildcard () async {
581
+ var code = '''
582
+ int _ = 0;
583
+ int f(int _) => _;
584
+ ''' ;
585
+ await resolveTestCode (code);
586
+
587
+ var parameter = findElement.parameter ('_' );
588
+ var parameterMatches = await searchEngine.searchReferences (parameter);
589
+ expect (parameterMatches, isEmpty);
590
+
591
+ var topLevelVariable = findElement.topVar ('_' );
592
+ var topLevelVariableMatches =
593
+ await searchEngine.searchReferences (topLevelVariable);
594
+ expect (
595
+ topLevelVariableMatches,
596
+ unorderedEquals ([
597
+ predicate ((SearchMatch m) {
598
+ return m.kind == MatchKind .READ &&
599
+ identical (m.element, findElement.topFunction ('f' )) &&
600
+ m.sourceRange.offset == code.indexOf ('_;' ) &&
601
+ m.sourceRange.length == '_' .length;
602
+ }),
603
+ ]),
604
+ );
605
+ }
606
+
607
+ Future <void > test_searchReferences_parameter_wildcard () async {
608
+ var code = '''
609
+ f(int _) {}
610
+ ''' ;
611
+ await resolveTestCode (code);
612
+
613
+ var element = findElement.parameter ('_' );
614
+ var matches = await searchEngine.searchReferences (element);
615
+
616
+ // No crashes.
617
+ expect (matches, isEmpty);
618
+ }
619
+
580
620
Future <void >
581
621
test_searchReferences_topFunction_parameter_optionalNamed_anywhere () async {
582
622
var code = '''
@@ -603,6 +643,54 @@ void g() {
603
643
);
604
644
}
605
645
646
+ Future <void > test_searchReferences_underscoreField () async {
647
+ var code = '''
648
+ class A {
649
+ final _ = 1;
650
+ int a() => _;
651
+ }
652
+ ''' ;
653
+ await resolveTestCode (code);
654
+
655
+ var element = findElement.field ('_' );
656
+ var matches = await searchEngine.searchReferences (element);
657
+
658
+ expect (
659
+ matches,
660
+ unorderedEquals ([
661
+ predicate ((SearchMatch m) {
662
+ return m.kind == MatchKind .READ &&
663
+ identical (m.element, findElement.method ('a' )) &&
664
+ m.sourceRange.offset == code.indexOf ('_;' ) &&
665
+ m.sourceRange.length == '_' .length;
666
+ }),
667
+ ]),
668
+ );
669
+ }
670
+
671
+ Future <void > test_searchReferences_underscoreTopLevelVariable () async {
672
+ var code = '''
673
+ final _ = 1;
674
+ int f() => _;
675
+ ''' ;
676
+ await resolveTestCode (code);
677
+
678
+ var element = findElement.topVar ('_' );
679
+ var matches = await searchEngine.searchReferences (element);
680
+
681
+ expect (
682
+ matches,
683
+ unorderedEquals ([
684
+ predicate ((SearchMatch m) {
685
+ return m.kind == MatchKind .READ &&
686
+ identical (m.element, findElement.topFunction ('f' )) &&
687
+ m.sourceRange.offset == code.indexOf ('_;' ) &&
688
+ m.sourceRange.length == '_' .length;
689
+ }),
690
+ ]),
691
+ );
692
+ }
693
+
606
694
Future <void > test_searchTopLevelDeclarations () async {
607
695
newFile ('$testPackageLibPath /a.dart' , '''
608
696
class A {}
0 commit comments