mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Fixed an assert caused when a TupleExpr that didn't have a valid SourceRange had a valid SourceLoc for the first element but not for the last
This commit is contained in:
@@ -1314,18 +1314,32 @@ SequenceExpr *SequenceExpr::create(ASTContext &ctx, ArrayRef<Expr*> elements) {
|
||||
return ::new(Buffer) SequenceExpr(elements);
|
||||
}
|
||||
|
||||
SourceLoc TupleExpr::getStartLoc() const {
|
||||
if (LParenLoc.isValid()) return LParenLoc;
|
||||
if (getNumElements() == 0) return SourceLoc();
|
||||
return getElement(0)->getStartLoc();
|
||||
}
|
||||
|
||||
SourceLoc TupleExpr::getEndLoc() const {
|
||||
if (hasTrailingClosure() || RParenLoc.isInvalid()) {
|
||||
if (getNumElements() == 0) return SourceLoc();
|
||||
return getElements().back()->getEndLoc();
|
||||
SourceRange TupleExpr::getSourceRange() const {
|
||||
SourceLoc start = SourceLoc();
|
||||
SourceLoc end = SourceLoc();
|
||||
if (LParenLoc.isValid()) {
|
||||
start = LParenLoc;
|
||||
} else if (getNumElements() == 0) {
|
||||
return { SourceLoc(), SourceLoc() };
|
||||
} else {
|
||||
start = getElement(0)->getStartLoc();
|
||||
}
|
||||
|
||||
if (hasTrailingClosure() || RParenLoc.isInvalid()) {
|
||||
if (getNumElements() == 0) {
|
||||
return { SourceLoc(), SourceLoc() };
|
||||
} else {
|
||||
end = getElements().back()->getEndLoc();
|
||||
}
|
||||
} else {
|
||||
end = RParenLoc;
|
||||
}
|
||||
|
||||
if (start.isValid() && end.isValid()) {
|
||||
return { start, end };
|
||||
} else {
|
||||
return { SourceLoc(), SourceLoc() };
|
||||
}
|
||||
return RParenLoc;
|
||||
}
|
||||
|
||||
TupleExpr::TupleExpr(SourceLoc LParenLoc, ArrayRef<Expr *> SubExprs,
|
||||
|
||||
Reference in New Issue
Block a user