@@ -20,6 +20,7 @@ private let rowCharWidth: Int = 30
2020@_cdecl ( " swift_ASTGen_validateUnqualifiedLookup " )
2121public func unqualifiedLookup(
2222 sourceFilePtr: UnsafeRawPointer ,
23+ astContext: BridgedASTContext ,
2324 lookupAt: BridgedSourceLoc ,
2425 finishInSequentialScope: Bool ,
2526 astScopeResultRef: BridgedArrayRef
@@ -29,6 +30,11 @@ public func unqualifiedLookup(
2930 let sourceFileSyntax = sourceFile. pointee. syntax
3031 let sourceLocationConverter = sourceFile. pointee. sourceLocationConverter
3132
33+ let buildConfiguration = CompilerBuildConfiguration (
34+ ctx: astContext,
35+ sourceBuffer: sourceFile. pointee. buffer
36+ )
37+
3238 guard let lookupPosition = sourceFile. pointee. position ( of: lookupAt) ,
3339 let lookupToken = sourceFileSyntax. token ( at: lookupPosition)
3440 else {
@@ -37,10 +43,17 @@ public func unqualifiedLookup(
3743 }
3844
3945 // Map AST result
40- let astResults = astConsumedResults ( sourceFile: sourceFile, astScopeResultRef: astScopeResultRef)
46+ let astResults = astConsumedResults (
47+ sourceFile: sourceFile,
48+ astScopeResultRef: astScopeResultRef
49+ )
4150
4251 // Map SLL result
43- let sllResults = sllConsumedResults ( lookupToken: lookupToken, finishInSequentialScope: finishInSequentialScope)
52+ let sllResults = sllConsumedResults (
53+ lookupToken: lookupToken,
54+ finishInSequentialScope: finishInSequentialScope,
55+ buildConfiguration: buildConfiguration
56+ )
4457
4558 // Add header to the output
4659 var consoleOutput = " -----> Lookup started at: \( sourceLocationConverter. location ( for: lookupPosition) . lineWithColumn) ( \" \( lookupToken. text) \" ) finishInSequentialScope: \( finishInSequentialScope) \n "
@@ -99,6 +112,8 @@ private func isInvalidFirstNameInDeclarationIntroduction(
99112 SwitchCaseSyntax . self,
100113 ClosureExprSyntax . self,
101114 AccessorDeclSyntax . self,
115+ AccessorBlockSyntax . self,
116+ ForStmtSyntax . self,
102117 PatternBindingSyntax . self
103118 ]
104119
@@ -151,9 +166,10 @@ private func astConsumedResults(
151166/// the results an array of `ConsumedLookupResult`. Introduces appropriate flags.
152167private func sllConsumedResults(
153168 lookupToken: TokenSyntax ,
154- finishInSequentialScope: Bool
169+ finishInSequentialScope: Bool ,
170+ buildConfiguration: CompilerBuildConfiguration
155171) -> [ ConsumedLookupResult ] {
156- lookupToken. lookup ( nil , with: LookupConfig ( finishInSequentialScope: finishInSequentialScope) )
172+ lookupToken. lookup ( nil , with: LookupConfig ( finishInSequentialScope: finishInSequentialScope, buildConfiguration : buildConfiguration ) )
157173 . flatMap { result in
158174 switch result {
159175 case . lookInMembers( let lookInMembers) :
@@ -176,9 +192,15 @@ private func sllConsumedResults(
176192 ) ]
177193 default :
178194 if let parent = result. scope. parent, result. scope. is ( GenericParameterClauseSyntax . self) {
179- if ( parent. is ( FunctionDeclSyntax . self) ||
180- parent. is ( SubscriptDeclSyntax . self) ||
181- result. scope. range. contains ( lookupToken. position) ) {
195+ if let parentFunctionDecl = parent. as ( FunctionDeclSyntax . self) ,
196+ parentFunctionDecl. attributes. range. contains ( lookupToken. position) {
197+ // If lookup started fron function attributes, don't reverse
198+ return result. names. map { name in
199+ ConsumedLookupResult ( rawName: name. identifier? . name ?? " " , position: name. position, flags: [ ] )
200+ }
201+ } else if parent. is ( FunctionDeclSyntax . self) ||
202+ parent. is ( SubscriptDeclSyntax . self) ||
203+ result. scope. range. contains ( lookupToken. position) {
182204 // If a result from function generic parameter clause or lookup started within it, reverse introduced names.
183205 return result. names. reversed ( ) . map { name in
184206 ConsumedLookupResult ( rawName: name. identifier? . name ?? " " , position: name. position, flags: . placementRearranged)
@@ -188,6 +210,15 @@ private func sllConsumedResults(
188210 return result. names. reversed ( ) . map { name in
189211 ConsumedLookupResult ( rawName: name. identifier? . name ?? " " , position: name. position, flags: . placementRearranged)
190212 }
213+ } else if let initializerDecl = parent. as ( InitializerDeclSyntax . self) ,
214+ initializerDecl. range. contains ( lookupToken. position) {
215+ return result. names. reversed ( ) . map { name in
216+ ConsumedLookupResult ( rawName: name. identifier? . name ?? " " , position: name. position, flags: . placementRearranged)
217+ }
218+ } else if parent. is ( TypeAliasDeclSyntax . self) {
219+ return result. names. reversed ( ) . map { name in
220+ ConsumedLookupResult ( rawName: name. identifier? . name ?? " " , position: name. position, flags: . placementRearranged)
221+ }
191222 }
192223
193224 // No flags or reorderings to perform.
0 commit comments