Skip to content

Commit efef86d

Browse files
authored
Merge pull request #7042 from mxswd/assign-expr-getloc
Fall back to the AssignExprs startLoc when the EqualLoc is invalid
2 parents aa33dc5 + 9edb936 commit efef86d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

include/swift/AST/Expr.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4331,7 +4331,13 @@ class AssignExpr : public Expr {
43314331

43324332
SourceLoc getEqualLoc() const { return EqualLoc; }
43334333

4334-
SourceLoc getLoc() const { return EqualLoc; }
4334+
SourceLoc getLoc() const {
4335+
SourceLoc loc = EqualLoc;
4336+
if (loc.isValid()) {
4337+
return loc;
4338+
}
4339+
return getStartLoc();
4340+
}
43354341
SourceLoc getStartLoc() const {
43364342
if (!isFolded()) return EqualLoc;
43374343
return ( Dest->getStartLoc().isValid()

unittests/AST/SourceLocTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST(SourceLoc, AssignExpr) {
115115
/*implicit*/false);
116116
EXPECT_EQ(start, invalidSource->getStartLoc());
117117
EXPECT_EQ(SourceLoc(), invalidSource->getEqualLoc());
118-
EXPECT_EQ(SourceLoc(), invalidSource->getLoc());
118+
EXPECT_EQ(start, invalidSource->getLoc()); // If the equal loc is invalid, but start is valid, point at the start
119119
EXPECT_EQ(start.getAdvancedLoc(3), invalidSource->getEndLoc());
120120
EXPECT_EQ(SourceRange(start, start.getAdvancedLoc(3)),
121121
invalidSource->getSourceRange());
@@ -124,7 +124,7 @@ TEST(SourceLoc, AssignExpr) {
124124
/*implicit*/false);
125125
EXPECT_EQ(start.getAdvancedLoc(8), invalidDest->getStartLoc());
126126
EXPECT_EQ(SourceLoc(), invalidDest->getEqualLoc());
127-
EXPECT_EQ(SourceLoc(), invalidDest->getLoc());
127+
EXPECT_EQ(start.getAdvancedLoc(8), invalidDest->getLoc()); // If the equal loc is invalid, but start is valid, point at the start
128128
EXPECT_EQ(start.getAdvancedLoc(11), invalidDest->getEndLoc());
129129
EXPECT_EQ(SourceRange(start.getAdvancedLoc(8), start.getAdvancedLoc(11)),
130130
invalidDest->getSourceRange());

0 commit comments

Comments
 (0)