@@ -144,7 +144,7 @@ import SwiftSyntax
144
144
145
145
/// Capture, parameter and body names introduced in this scope.
146
146
@_spi ( Experimental) public var defaultIntroducedNames : [ LookupName ] {
147
- captureNames + parameterNames + introducedNamesInBody
147
+ parameterNames + captureNames + introducedNamesInBody
148
148
}
149
149
150
150
@_spi ( Experimental) public var scopeDebugName : String {
@@ -202,7 +202,7 @@ import SwiftSyntax
202
202
} else {
203
203
signatureResults = LookupResult . getResultArray (
204
204
for: self ,
205
- withNames: ( captureNames + parameterNames ) . filter { name in
205
+ withNames: ( parameterNames + captureNames ) . filter { name in
206
206
checkIdentifier ( identifier, refersTo: name, at: lookUpPosition)
207
207
}
208
208
)
@@ -638,7 +638,7 @@ import SwiftSyntax
638
638
checkIdentifier ( identifier, refersTo: name, at: lookUpPosition)
639
639
}
640
640
641
- if label. range. contains ( lookUpPosition) {
641
+ if label. range. contains ( lookUpPosition) && !isInWhereClause ( lookUpPosition : lookUpPosition ) {
642
642
return config. finishInSequentialScope ? [ ] : lookupInParent ( identifier, at: lookUpPosition, with: config)
643
643
} else if config. finishInSequentialScope {
644
644
return sequentialLookup (
@@ -660,6 +660,20 @@ import SwiftSyntax
660
660
+ lookupInParent( identifier, at: lookUpPosition, with: config)
661
661
}
662
662
}
663
+
664
+ /// Returns `true` if `lookUpPosition` is inside a `where`
665
+ /// clause associated with one of the case items of this scope.
666
+ private func isInWhereClause( lookUpPosition: AbsolutePosition ) -> Bool {
667
+ guard let switchCaseItemList = label. as ( SwitchCaseLabelSyntax . self) ? . caseItems else { return false }
668
+
669
+ for item in switchCaseItemList {
670
+ if item. whereClause? . range. contains ( lookUpPosition) ?? false {
671
+ return true
672
+ }
673
+ }
674
+
675
+ return false
676
+ }
663
677
}
664
678
665
679
@_spi ( Experimental) extension ProtocolDeclSyntax : ScopeSyntax , LookInMembersScopeSyntax {
@@ -934,7 +948,9 @@ extension SubscriptDeclSyntax: WithGenericParametersScopeSyntax, CanInterleaveRe
934
948
at lookUpPosition: AbsolutePosition ,
935
949
with config: LookupConfig
936
950
) -> [ LookupResult ] {
937
- if bindings. first? . accessorBlock? . range. contains ( lookUpPosition) ?? false {
951
+ if ( bindings. first? . accessorBlock? . range. contains ( lookUpPosition) ?? false )
952
+ || shouldIntroduceSelfIfLazy ( lookUpPosition: lookUpPosition)
953
+ {
938
954
return defaultLookupImplementation (
939
955
in: ( isMember ? [ . implicit( . self ( self ) ) ] : LookupName . getNames ( from: self ) ) ,
940
956
identifier,
@@ -960,6 +976,16 @@ extension SubscriptDeclSyntax: WithGenericParametersScopeSyntax, CanInterleaveRe
960
976
961
977
return resultsToInterleave + lookupInParent( identifier, at: lookUpPosition, with: config)
962
978
}
979
+
980
+ /// Returns `true`, if `lookUpPosition` is in initializer of
981
+ /// this variable declaration and the declaration is lazy.
982
+ private func shouldIntroduceSelfIfLazy( lookUpPosition: AbsolutePosition ) -> Bool {
983
+ guard bindings. first? . initializer? . range. contains ( lookUpPosition) ?? false else { return false }
984
+
985
+ return modifiers. contains {
986
+ $0. name. tokenKind == . keyword( . lazy)
987
+ }
988
+ }
963
989
}
964
990
965
991
@_spi ( Experimental) extension DeinitializerDeclSyntax : ScopeSyntax {
0 commit comments