diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 58ee42519cba9..60dcc41476b52 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1224,16 +1224,6 @@ ERROR(expected_type_after_as,none, ERROR(string_interpolation_extra,none, "extra tokens after interpolated string expression", ()) -// Interpolated value accidentally forms a tuple. -ERROR(string_interpolation_single_expr,none, - "interpolations should be a single expression", ()) -NOTE(string_interpolation_form_tuple,none, - "insert parentheses to form a tuple", ()) -NOTE(string_interpolation_delete_empty,none, - "delete empty interpolation", ()) -ERROR(string_interpolation_keyword_argument,PointsToFirstBadToken, - "interpolations cannot start with a keyword argument", ()) - // Keypath expressions. ERROR(expr_keypath_expected_lparen,PointsToFirstBadToken, "expected '(' following '#keyPath'", ()) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index eb582851aa793..9b464c2bd9ff0 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1907,50 +1907,6 @@ parseStringSegments(SmallVectorImpl &Segments, Status |= E; if (E.isNonNull()) { Exprs.push_back(E.get()); - - if (auto tuple = dyn_cast(Exprs.back())) { - // If parseExprList() returns a TupleExpr instead of a ParenExpr, - // the interpolation must have had an argument label, or the wrong - // number of elements, or both. Reject these. - if (tuple->getNumElements() > 1) { - SourceLoc StartLoc = tuple->getStartLoc(); - SourceLoc SecondExprLoc = tuple->getElement(1)->getStartLoc(); - SourceLoc EndLoc = tuple->getEndLoc(); - - diagnose(SecondExprLoc, diag::string_interpolation_single_expr); - diagnose(StartLoc, diag::string_interpolation_form_tuple) - .fixItInsert(StartLoc, "(") - .fixItInsertAfter(EndLoc, ")"); - - Exprs.back() = - new (Context) ParenExpr(SourceLoc(), tuple, SourceLoc(), - /*hasTrailingClosure=*/false); - } else if (tuple->getNumElements() == 1 && - !tuple->getElementName(0).empty()) { - SourceLoc NameStart = tuple->getElementNameLoc(0); - SourceLoc ArgStart = tuple->getElement(0)->getStartLoc(); - - diagnose(NameStart, diag::string_interpolation_keyword_argument) - .fixItRemoveChars(NameStart, ArgStart); - - Exprs.back() = - new (Context) ParenExpr(tuple->getLParenLoc(), tuple->getElement(0), - tuple->getRParenLoc(), /*hasTrailingClosure=*/false); - } else if (tuple->getNumElements() == 0 && !Status.isError()) { - SourceLoc StartLoc = tuple->getStartLoc(); - SourceLoc EndLoc = tuple->getEndLoc(); - SourceLoc SlashLoc = StartLoc.getAdvancedLocOrInvalid(-1); - - diagnose(EndLoc, diag::string_interpolation_single_expr); - diagnose(SlashLoc, diag::string_interpolation_delete_empty) - .fixItRemoveChars(SlashLoc, EndLoc.getAdvancedLocOrInvalid(1)); - - auto Error = new (Context) ErrorExpr(SourceRange(EndLoc, EndLoc)); - Exprs.back() = - new (Context) ParenExpr(SourceLoc(), Error, SourceLoc(), - /*hasTrailingClosure=*/false); - } - } if (!Tok.is(tok::eof)) { diagnose(Tok, diag::string_interpolation_extra); diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index ed2537bcb175e..5446f6156a122 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -902,10 +902,6 @@ ParserStatus Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc, bool AllowSepAfterLast, Diag<> ErrorDiag, SyntaxKind Kind, llvm::function_ref callback) { - auto TokIsStringInterpolationEOF = [&]() -> bool { - return Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren; - }; - llvm::Optional ListContext; ListContext.emplace(SyntaxContext, Kind); if (Kind == SyntaxKind::Unknown) @@ -918,10 +914,6 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc, RightLoc = consumeToken(RightK); return makeParserSuccess(); } - if (TokIsStringInterpolationEOF()) { - RightLoc = Tok.getLoc(); - return makeParserSuccess(); - } ParserStatus Status; while (true) { @@ -941,7 +933,7 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc, // If the lexer stopped with an EOF token whose spelling is ")", then this // is actually the tuple that is a string literal interpolation context. // Just accept the ")" and build the tuple as we usually do. - if (TokIsStringInterpolationEOF()) { + if (Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren) { RightLoc = Tok.getLoc(); return Status; } diff --git a/test/Parse/interpolation_tuple_errors.swift b/test/Parse/interpolation_tuple_errors.swift deleted file mode 100644 index a2404cefb787f..0000000000000 --- a/test/Parse/interpolation_tuple_errors.swift +++ /dev/null @@ -1,26 +0,0 @@ -// RUN: %target-typecheck-verify-swift - -let str = "a" - -// Test with too many interpolated values. -func papaBear() { - _ = "\(str, str)" // expected-error{{interpolations should be a single expression}} expected-note {{insert parentheses to form a tuple}} {{9-9=(}} {{19-19=)}} -} - -// Test with too few interpolated values. -func mamaBear() { - _ = "\()" // expected-error{{interpolations should be a single expression}} expected-note {{delete empty interpolation}} {{8-11=}} -} - -// Test with the correct number of interpolated values. -func babyBear() { - _ = "\(str)" -} - -// Test with an argument label -func funkyBear() { - _ = "\(describing: str)" // expected-error{{interpolations cannot start with a keyword argument}} {{10-22=}} - _ = "\(format: str)" // expected-error{{interpolations cannot start with a keyword argument}} {{10-18=}} - _ = "\(validatingUTF8: str)" // expected-error{{interpolations cannot start with a keyword argument}} {{10-26=}} - _ = "\(fnord: str)" // expected-error{{interpolations cannot start with a keyword argument}} {{10-17=}} -} diff --git a/validation-test/compiler_crashers_2_fixed/0160-sr7958.swift b/validation-test/compiler_crashers_2/0160-sr7958.swift similarity index 74% rename from validation-test/compiler_crashers_2_fixed/0160-sr7958.swift rename to validation-test/compiler_crashers_2/0160-sr7958.swift index 4c6201418b3d0..cbf999cc9c9fd 100644 --- a/validation-test/compiler_crashers_2_fixed/0160-sr7958.swift +++ b/validation-test/compiler_crashers_2/0160-sr7958.swift @@ -1,4 +1,4 @@ -// RUN: not %target-swift-frontend %s -emit-ir +// RUN: not --crash %target-swift-frontend %s -emit-ir func foo(_ x: U?) { _ = "\(anyLabelHere: x)"