Skip to content

Commit 8ea6cfb

Browse files
authored
Merge pull request #7079 from mxswd/swift-3.1-branch
[Swift 3.1 branch] Fall back to the AssignExprs startLoc when the EqualLoc is invalid
2 parents 7e8a171 + 06c8121 commit 8ea6cfb

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
@@ -4343,7 +4343,13 @@ class AssignExpr : public Expr {
43434343

43444344
SourceLoc getEqualLoc() const { return EqualLoc; }
43454345

4346-
SourceLoc getLoc() const { return EqualLoc; }
4346+
SourceLoc getLoc() const {
4347+
SourceLoc loc = EqualLoc;
4348+
if (loc.isValid()) {
4349+
return loc;
4350+
}
4351+
return getStartLoc();
4352+
}
43474353
SourceLoc getStartLoc() const {
43484354
if (!isFolded()) return EqualLoc;
43494355
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)