Skip to content

Commit ba4949b

Browse files
authored
Merge pull request #17190 from CodaFi/revert-labels-are-so-reductive
Revert "Reject bad string interpolations (#17074)"
2 parents 3b03111 + dfe42d2 commit ba4949b

File tree

5 files changed

+2
-90
lines changed

5 files changed

+2
-90
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,16 +1224,6 @@ ERROR(expected_type_after_as,none,
12241224
ERROR(string_interpolation_extra,none,
12251225
"extra tokens after interpolated string expression", ())
12261226

1227-
// Interpolated value accidentally forms a tuple.
1228-
ERROR(string_interpolation_single_expr,none,
1229-
"interpolations should be a single expression", ())
1230-
NOTE(string_interpolation_form_tuple,none,
1231-
"insert parentheses to form a tuple", ())
1232-
NOTE(string_interpolation_delete_empty,none,
1233-
"delete empty interpolation", ())
1234-
ERROR(string_interpolation_keyword_argument,PointsToFirstBadToken,
1235-
"interpolations cannot start with a keyword argument", ())
1236-
12371227
// Keypath expressions.
12381228
ERROR(expr_keypath_expected_lparen,PointsToFirstBadToken,
12391229
"expected '(' following '#keyPath'", ())

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,50 +1907,6 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
19071907
Status |= E;
19081908
if (E.isNonNull()) {
19091909
Exprs.push_back(E.get());
1910-
1911-
if (auto tuple = dyn_cast<TupleExpr>(Exprs.back())) {
1912-
// If parseExprList() returns a TupleExpr instead of a ParenExpr,
1913-
// the interpolation must have had an argument label, or the wrong
1914-
// number of elements, or both. Reject these.
1915-
if (tuple->getNumElements() > 1) {
1916-
SourceLoc StartLoc = tuple->getStartLoc();
1917-
SourceLoc SecondExprLoc = tuple->getElement(1)->getStartLoc();
1918-
SourceLoc EndLoc = tuple->getEndLoc();
1919-
1920-
diagnose(SecondExprLoc, diag::string_interpolation_single_expr);
1921-
diagnose(StartLoc, diag::string_interpolation_form_tuple)
1922-
.fixItInsert(StartLoc, "(")
1923-
.fixItInsertAfter(EndLoc, ")");
1924-
1925-
Exprs.back() =
1926-
new (Context) ParenExpr(SourceLoc(), tuple, SourceLoc(),
1927-
/*hasTrailingClosure=*/false);
1928-
} else if (tuple->getNumElements() == 1 &&
1929-
!tuple->getElementName(0).empty()) {
1930-
SourceLoc NameStart = tuple->getElementNameLoc(0);
1931-
SourceLoc ArgStart = tuple->getElement(0)->getStartLoc();
1932-
1933-
diagnose(NameStart, diag::string_interpolation_keyword_argument)
1934-
.fixItRemoveChars(NameStart, ArgStart);
1935-
1936-
Exprs.back() =
1937-
new (Context) ParenExpr(tuple->getLParenLoc(), tuple->getElement(0),
1938-
tuple->getRParenLoc(), /*hasTrailingClosure=*/false);
1939-
} else if (tuple->getNumElements() == 0 && !Status.isError()) {
1940-
SourceLoc StartLoc = tuple->getStartLoc();
1941-
SourceLoc EndLoc = tuple->getEndLoc();
1942-
SourceLoc SlashLoc = StartLoc.getAdvancedLocOrInvalid(-1);
1943-
1944-
diagnose(EndLoc, diag::string_interpolation_single_expr);
1945-
diagnose(SlashLoc, diag::string_interpolation_delete_empty)
1946-
.fixItRemoveChars(SlashLoc, EndLoc.getAdvancedLocOrInvalid(1));
1947-
1948-
auto Error = new (Context) ErrorExpr(SourceRange(EndLoc, EndLoc));
1949-
Exprs.back() =
1950-
new (Context) ParenExpr(SourceLoc(), Error, SourceLoc(),
1951-
/*hasTrailingClosure=*/false);
1952-
}
1953-
}
19541910

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

lib/Parse/Parser.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,6 @@ ParserStatus
902902
Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
903903
bool AllowSepAfterLast, Diag<> ErrorDiag, SyntaxKind Kind,
904904
llvm::function_ref<ParserStatus()> callback) {
905-
auto TokIsStringInterpolationEOF = [&]() -> bool {
906-
return Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren;
907-
};
908-
909905
llvm::Optional<SyntaxParsingContext> ListContext;
910906
ListContext.emplace(SyntaxContext, Kind);
911907
if (Kind == SyntaxKind::Unknown)
@@ -918,10 +914,6 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
918914
RightLoc = consumeToken(RightK);
919915
return makeParserSuccess();
920916
}
921-
if (TokIsStringInterpolationEOF()) {
922-
RightLoc = Tok.getLoc();
923-
return makeParserSuccess();
924-
}
925917

926918
ParserStatus Status;
927919
while (true) {
@@ -941,7 +933,7 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
941933
// If the lexer stopped with an EOF token whose spelling is ")", then this
942934
// is actually the tuple that is a string literal interpolation context.
943935
// Just accept the ")" and build the tuple as we usually do.
944-
if (TokIsStringInterpolationEOF()) {
936+
if (Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren) {
945937
RightLoc = Tok.getLoc();
946938
return Status;
947939
}

test/Parse/interpolation_tuple_errors.swift

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

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

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

0 commit comments

Comments
 (0)