@@ -508,22 +508,18 @@ import SwiftSyntax
508
508
@_spi ( Experimental) extension AccessorDeclSyntax : ScopeSyntax {
509
509
/// Implicit and/or explicit names introduced within the accessor.
510
510
@_spi ( Experimental) public var introducedNames : [ LookupName ] {
511
- let names : [ LookupName ]
512
-
513
511
if let parameters {
514
- names = LookupName . getNames ( from: parameters)
512
+ return LookupName . getNames ( from: parameters)
515
513
} else {
516
514
switch accessorSpecifier. tokenKind {
517
515
case . keyword( . set) , . keyword( . willSet) :
518
- names = [ . implicit( . newValue( self ) ) ]
516
+ return [ . implicit( . newValue( self ) ) ]
519
517
case . keyword( . didSet) :
520
- names = [ . implicit( . oldValue( self ) ) ]
518
+ return [ . implicit( . oldValue( self ) ) ]
521
519
default :
522
- names = [ ]
520
+ return [ ]
523
521
}
524
522
}
525
-
526
- return names
527
523
}
528
524
529
525
@_spi ( Experimental) public var scopeDebugName : String {
@@ -539,7 +535,10 @@ import SwiftSyntax
539
535
at lookUpPosition: AbsolutePosition ,
540
536
with config: LookupConfig
541
537
) -> [ LookupResult ] {
542
- guard let parentAccessorBlockScope = parentScope? . as ( AccessorBlockSyntax . self) else {
538
+ guard let parentScope,
539
+ let canInterleaveLaterScope = Syntax ( parentScope) . asProtocol ( SyntaxProtocol . self)
540
+ as? CanInterleaveResultsLaterScopeSyntax
541
+ else {
543
542
return defaultLookupImplementation ( identifier, at: lookUpPosition, with: config)
544
543
}
545
544
@@ -554,7 +553,7 @@ import SwiftSyntax
554
553
with: config,
555
554
propagateToParent: false
556
555
)
557
- + parentAccessorBlockScope . interleaveAccessorResultsAfterSubscriptLookup (
556
+ + canInterleaveLaterScope . lookupWithInterleavedResults (
558
557
identifier,
559
558
at: lookUpPosition,
560
559
with: config,
@@ -701,7 +700,8 @@ import SwiftSyntax
701
700
}
702
701
}
703
702
704
- @_spi ( Experimental) extension SubscriptDeclSyntax : WithGenericParametersScopeSyntax {
703
+ @_spi ( Experimental)
704
+ extension SubscriptDeclSyntax : WithGenericParametersScopeSyntax , CanInterleaveResultsLaterScopeSyntax {
705
705
/// Parameters introduced by this subscript and possibly `self` keyword.
706
706
@_spi ( Experimental) public var introducedNames : [ LookupName ] {
707
707
let parameters = parameterClause. parameters. flatMap { parameter in
@@ -726,7 +726,7 @@ import SwiftSyntax
726
726
at lookUpPosition: AbsolutePosition ,
727
727
with config: LookupConfig
728
728
) -> [ LookupResult ] {
729
- interleaveResultsAfterThisSubscriptLookup (
729
+ lookupWithInterleavedResults (
730
730
identifier,
731
731
at: lookUpPosition,
732
732
with: config,
@@ -753,7 +753,7 @@ import SwiftSyntax
753
753
/// introduced at the boundary of the getter. That's why
754
754
/// this function needs to ensure the implicit `self` passed
755
755
/// from inside the accessor block is added after `subscript` parameters.
756
- func interleaveResultsAfterThisSubscriptLookup (
756
+ func lookupWithInterleavedResults (
757
757
_ identifier: Identifier ? ,
758
758
at lookUpPosition: AbsolutePosition ,
759
759
with config: LookupConfig ,
@@ -779,7 +779,7 @@ import SwiftSyntax
779
779
}
780
780
}
781
781
782
- @_spi ( Experimental) extension AccessorBlockSyntax : SequentialScopeSyntax {
782
+ @_spi ( Experimental) extension AccessorBlockSyntax : SequentialScopeSyntax , CanInterleaveResultsLaterScopeSyntax {
783
783
/// Names from the accessors or
784
784
/// getters of this accessor block scope.
785
785
@_spi ( Experimental) public var introducedNames : [ LookupName ] {
@@ -815,17 +815,20 @@ import SwiftSyntax
815
815
816
816
/// Used by children accessors to interleave
817
817
/// their results with parent `subscript` declaration scope.
818
- func interleaveAccessorResultsAfterSubscriptLookup (
818
+ func lookupWithInterleavedResults (
819
819
_ identifier: Identifier ? ,
820
820
at lookUpPosition: AbsolutePosition ,
821
821
with config: LookupConfig ,
822
822
resultsToInterleave: [ LookupResult ]
823
823
) -> [ LookupResult ] {
824
- guard let parentSubscriptScope = parentScope? . as ( SubscriptDeclSyntax . self) else {
824
+ guard let parentScope,
825
+ let canInterleaveLaterScope = Syntax ( parentScope) . asProtocol ( SyntaxProtocol . self)
826
+ as? CanInterleaveResultsLaterScopeSyntax
827
+ else {
825
828
return lookupInParent ( identifier, at: lookUpPosition, with: config)
826
829
}
827
830
828
- return parentSubscriptScope . interleaveResultsAfterThisSubscriptLookup (
831
+ return canInterleaveLaterScope . lookupWithInterleavedResults (
829
832
identifier,
830
833
at: lookUpPosition,
831
834
with: config,
@@ -845,7 +848,7 @@ import SwiftSyntax
845
848
}
846
849
}
847
850
848
- @_spi ( Experimental) extension VariableDeclSyntax : ScopeSyntax {
851
+ @_spi ( Experimental) extension VariableDeclSyntax : CanInterleaveResultsLaterScopeSyntax {
849
852
/// Variable decl scope doesn't introduce any
850
853
/// names unless it is a member and is looked
851
854
/// up from inside it's accessor block.
@@ -879,4 +882,17 @@ import SwiftSyntax
879
882
return lookupInParent ( identifier, at: lookUpPosition, with: config)
880
883
}
881
884
}
885
+
886
+ func lookupWithInterleavedResults(
887
+ _ identifier: Identifier ? ,
888
+ at lookUpPosition: AbsolutePosition ,
889
+ with config: LookupConfig ,
890
+ resultsToInterleave: [ LookupResult ]
891
+ ) -> [ LookupResult ] {
892
+ guard parentScope? . is ( MemberBlockSyntax . self) ?? false else {
893
+ return lookupInParent ( identifier, at: lookUpPosition, with: config)
894
+ }
895
+
896
+ return resultsToInterleave + lookupInParent( identifier, at: lookUpPosition, with: config)
897
+ }
882
898
}
0 commit comments