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:
Maxwell Swadling
2016-10-08 23:10:37 -07:00
parent d9fe1d0840
commit 339e40fb02
3 changed files with 69 additions and 13 deletions

View File

@@ -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,