@@ -508,22 +508,18 @@ import SwiftSyntax
508508@_spi ( Experimental) extension AccessorDeclSyntax : ScopeSyntax {
509509 /// Implicit and/or explicit names introduced within the accessor.
510510 @_spi ( Experimental) public var introducedNames : [ LookupName ] {
511- let names : [ LookupName ]
512-
513511 if let parameters {
514- names = LookupName . getNames ( from: parameters)
512+ return LookupName . getNames ( from: parameters)
515513 } else {
516514 switch accessorSpecifier. tokenKind {
517515 case . keyword( . set) , . keyword( . willSet) :
518- names = [ . implicit( . newValue( self ) ) ]
516+ return [ . implicit( . newValue( self ) ) ]
519517 case . keyword( . didSet) :
520- names = [ . implicit( . oldValue( self ) ) ]
518+ return [ . implicit( . oldValue( self ) ) ]
521519 default :
522- names = [ ]
520+ return [ ]
523521 }
524522 }
525-
526- return names
527523 }
528524
529525 @_spi ( Experimental) public var scopeDebugName : String {
@@ -539,7 +535,10 @@ import SwiftSyntax
539535 at lookUpPosition: AbsolutePosition ,
540536 with config: LookupConfig
541537 ) -> [ 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 {
543542 return defaultLookupImplementation ( identifier, at: lookUpPosition, with: config)
544543 }
545544
@@ -554,7 +553,7 @@ import SwiftSyntax
554553 with: config,
555554 propagateToParent: false
556555 )
557- + parentAccessorBlockScope . interleaveAccessorResultsAfterSubscriptLookup (
556+ + canInterleaveLaterScope . lookupWithInterleavedResults (
558557 identifier,
559558 at: lookUpPosition,
560559 with: config,
@@ -701,7 +700,8 @@ import SwiftSyntax
701700 }
702701}
703702
704- @_spi ( Experimental) extension SubscriptDeclSyntax : WithGenericParametersScopeSyntax {
703+ @_spi ( Experimental)
704+ extension SubscriptDeclSyntax : WithGenericParametersScopeSyntax , CanInterleaveResultsLaterScopeSyntax {
705705 /// Parameters introduced by this subscript and possibly `self` keyword.
706706 @_spi ( Experimental) public var introducedNames : [ LookupName ] {
707707 let parameters = parameterClause. parameters. flatMap { parameter in
@@ -726,7 +726,7 @@ import SwiftSyntax
726726 at lookUpPosition: AbsolutePosition ,
727727 with config: LookupConfig
728728 ) -> [ LookupResult ] {
729- interleaveResultsAfterThisSubscriptLookup (
729+ lookupWithInterleavedResults (
730730 identifier,
731731 at: lookUpPosition,
732732 with: config,
@@ -753,7 +753,7 @@ import SwiftSyntax
753753 /// introduced at the boundary of the getter. That's why
754754 /// this function needs to ensure the implicit `self` passed
755755 /// from inside the accessor block is added after `subscript` parameters.
756- func interleaveResultsAfterThisSubscriptLookup (
756+ func lookupWithInterleavedResults (
757757 _ identifier: Identifier ? ,
758758 at lookUpPosition: AbsolutePosition ,
759759 with config: LookupConfig ,
@@ -779,7 +779,7 @@ import SwiftSyntax
779779 }
780780}
781781
782- @_spi ( Experimental) extension AccessorBlockSyntax : SequentialScopeSyntax {
782+ @_spi ( Experimental) extension AccessorBlockSyntax : SequentialScopeSyntax , CanInterleaveResultsLaterScopeSyntax {
783783 /// Names from the accessors or
784784 /// getters of this accessor block scope.
785785 @_spi ( Experimental) public var introducedNames : [ LookupName ] {
@@ -815,17 +815,20 @@ import SwiftSyntax
815815
816816 /// Used by children accessors to interleave
817817 /// their results with parent `subscript` declaration scope.
818- func interleaveAccessorResultsAfterSubscriptLookup (
818+ func lookupWithInterleavedResults (
819819 _ identifier: Identifier ? ,
820820 at lookUpPosition: AbsolutePosition ,
821821 with config: LookupConfig ,
822822 resultsToInterleave: [ LookupResult ]
823823 ) -> [ 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 {
825828 return lookupInParent ( identifier, at: lookUpPosition, with: config)
826829 }
827830
828- return parentSubscriptScope . interleaveResultsAfterThisSubscriptLookup (
831+ return canInterleaveLaterScope . lookupWithInterleavedResults (
829832 identifier,
830833 at: lookUpPosition,
831834 with: config,
@@ -845,7 +848,7 @@ import SwiftSyntax
845848 }
846849}
847850
848- @_spi ( Experimental) extension VariableDeclSyntax : ScopeSyntax {
851+ @_spi ( Experimental) extension VariableDeclSyntax : CanInterleaveResultsLaterScopeSyntax {
849852 /// Variable decl scope doesn't introduce any
850853 /// names unless it is a member and is looked
851854 /// up from inside it's accessor block.
@@ -879,4 +882,17 @@ import SwiftSyntax
879882 return lookupInParent ( identifier, at: lookUpPosition, with: config)
880883 }
881884 }
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+ }
882898}
0 commit comments