Skip to content

Commit f43240b

Browse files
authored
Merge pull request swiftlang#70576 from hborla/macro-lookup-fix
[ASTScope] Use the end location of the original source range of a macro expansion in `isBeforeInSource`.
2 parents 6d66211 + 8c9eeb2 commit f43240b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Basic/SourceLoc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,11 +797,11 @@ static bool isBeforeInSource(
797797
SourceLoc firstLocInLCA = firstMismatch == firstAncestors.end()
798798
? firstLoc
799799
: sourceMgr.getGeneratedSourceInfo(*firstMismatch)
800-
->originalSourceRange.getStart();
800+
->originalSourceRange.getEnd();
801801
SourceLoc secondLocInLCA = secondMismatch == secondAncestors.end()
802802
? secondLoc
803803
: sourceMgr.getGeneratedSourceInfo(*secondMismatch)
804-
->originalSourceRange.getStart();
804+
->originalSourceRange.getEnd();
805805
return sourceMgr.isBeforeInBuffer(firstLocInLCA, secondLocInLCA) ||
806806
(allowEqual && firstLocInLCA == secondLocInLCA);
807807
}

test/stdlib/Observation/Observable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ class RecursiveOuter {
215215
class GuardedAvailability {
216216
}
217217

218+
@Observable class TestASTScopeLCA {
219+
// Make sure ASTScope unqualified lookup can find local variables
220+
// inside initial values with closures when accessor macros are
221+
// involved.
222+
var state : Bool = {
223+
let value = true
224+
return value
225+
}()
226+
}
227+
218228
@main
219229
struct Validator {
220230
@MainActor

0 commit comments

Comments
 (0)