Skip to content

Commit 27dfa51

Browse files
committed
Wrap interpolated tuples in parens
Keeps them from being interpreted as parameter lists. Fixes SR-7958.
1 parent ba4949b commit 27dfa51

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,8 +1905,17 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
19051905
}
19061906

19071907
Status |= E;
1908-
if (E.isNonNull()) {
1909-
Exprs.push_back(E.get());
1908+
if (auto expr = E.getPtrOrNull()) {
1909+
if (auto tuple = dyn_cast<TupleExpr>(expr)) {
1910+
// This needs to be wrapped in a ParenExpr so it won't be interpreted
1911+
// as an argument list.
1912+
// FIXME: Do we want to warn/error about any of these cases?
1913+
expr = new (Context) ParenExpr(SourceLoc(), tuple, SourceLoc(),
1914+
/*hasTrailingClosure=*/false);
1915+
expr->setImplicit();
1916+
}
1917+
1918+
Exprs.push_back(expr);
19101919

19111920
if (!Tok.is(tok::eof)) {
19121921
diagnose(Tok, diag::string_interpolation_extra);

validation-test/compiler_crashers_2/0160-sr7958.swift renamed to validation-test/compiler_crashers_2_fixed/0160-sr7958.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -emit-ir
1+
// RUN: not %target-swift-frontend %s -emit-ir
22

33
func foo<U>(_ x: U?) {
44
_ = "\(anyLabelHere: x)"

0 commit comments

Comments
 (0)