@@ -1863,8 +1863,8 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
1863
1863
SyntaxKind::ExpressionSegment);
1864
1864
1865
1865
// Backslash is part of an expression segment.
1866
- Token BackSlash (tok::backslash,
1867
- CharSourceRange (Segment. Loc . getAdvancedLoc (- 1 ) , 1 ).str ());
1866
+ SourceLoc BackSlashLoc = Segment. Loc . getAdvancedLoc (- 1 );
1867
+ Token BackSlash (tok::backslash, CharSourceRange (BackSlashLoc , 1 ).str ());
1868
1868
ExprContext.addToken (BackSlash, EmptyTrivia, EmptyTrivia);
1869
1869
// Create a temporary lexer that lexes from the body of the string.
1870
1870
LexerState BeginState =
@@ -1888,30 +1888,12 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
1888
1888
TokReceiver->registerTokenKindChange (Tok.getLoc (),
1889
1889
tok::string_interpolation_anchor);
1890
1890
1891
- SourceLoc lParen, rParen;
1892
- SmallVector<Expr *, 4 > args;
1893
- SmallVector<Identifier, 4 > argLabels;
1894
- SmallVector<SourceLoc, 4 > argLabelLocs;
1895
- Expr *trailingClosureNeverPresent;
1896
- ParserStatus S =
1897
- parseExprList (tok::l_paren, tok::r_paren,
1898
- /* isPostfix=*/ false , /* isExprBasic=*/ true ,
1899
- lParen, args, argLabels, argLabelLocs, rParen,
1900
- trailingClosureNeverPresent,
1901
- SyntaxKind::FunctionCallArgumentList);
1902
- assert (!trailingClosureNeverPresent);
1903
-
1904
- Status |= S;
1905
- // If there was an error parsing a parameter, add an ErrorExpr to
1906
- // represent it. Prevents spurious errors about a nonexistent
1907
- // appendInterpolation() overload.
1908
- if (S.isError () && args.size () == 0 )
1909
- args.push_back (new (Context) ErrorExpr (SourceRange (lParen, rParen)));
1910
-
1911
- while (argLabels.size () < args.size ())
1912
- argLabels.push_back (Identifier ());
1913
- while (argLabelLocs.size () < args.size ())
1914
- argLabelLocs.push_back (SourceLoc ());
1891
+ auto callee = new (Context) UnresolvedDotExpr (InterpolationVarRef,
1892
+ /* dotloc=*/ BackSlashLoc,
1893
+ appendInterpolation,
1894
+ /* nameloc=*/ DeclNameLoc (),
1895
+ /* Implicit=*/ true );
1896
+ auto S = parseExprCallSuffix (makeParserResult (callee), true );
1915
1897
1916
1898
// If we stopped parsing the expression before the expression segment is
1917
1899
// over, eat the remaining tokens into a token list
@@ -1925,51 +1907,14 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
1925
1907
L->getLocForEndOfToken (SourceMgr, Tok.getLoc ()));
1926
1908
}
1927
1909
1910
+ Expr *call = S.getPtrOrNull ();
1911
+ if (!call)
1912
+ call = new (Context) ErrorExpr (SourceRange (Segment.Loc ,
1913
+ Segment.getEndLoc ()));
1914
+
1928
1915
InterpolationCount += 1 ;
1929
-
1930
- // In Swift 4.2 and earlier, a single argument with a label would ignore
1931
- // the label (at best), and multiple arguments would form a tuple.
1932
- if (!Context.isSwiftVersionAtLeast (5 )) {
1933
- if (args.size () > 1 ) {
1934
- diagnose (args[1 ]->getLoc (), diag::string_interpolation_list_changing)
1935
- .highlightChars (args[1 ]->getLoc (), rParen);
1936
- diagnose (args[1 ]->getLoc (),
1937
- diag::string_interpolation_list_insert_parens)
1938
- .fixItInsertAfter (lParen, " (" )
1939
- .fixItInsert (rParen, " )" );
1940
-
1941
- args = {
1942
- TupleExpr::create (Context,
1943
- lParen, args, argLabels, argLabelLocs, rParen,
1944
- /* hasTrailingClosure=*/ false ,
1945
- /* Implicit=*/ false )
1946
- };
1947
- argLabels = { Identifier () };
1948
- argLabelLocs = { SourceLoc () };
1949
- }
1950
- else if (args.size () == 1 && argLabels[0 ] != Identifier ()) {
1951
- diagnose (argLabelLocs[0 ], diag::string_interpolation_label_changing)
1952
- .highlightChars (argLabelLocs[0 ], args[0 ]->getStartLoc ());
1953
- diagnose (argLabelLocs[0 ], diag::string_interpolation_remove_label,
1954
- argLabels[0 ])
1955
- .fixItRemoveChars (argLabelLocs[0 ], args[0 ]->getStartLoc ());
1956
-
1957
- argLabels[0 ] = Identifier ();
1958
- }
1959
- }
1960
-
1961
- auto AppendInterpolationRef =
1962
- new (Context) UnresolvedDotExpr (InterpolationVarRef,
1963
- /* dotloc=*/ SourceLoc (),
1964
- appendInterpolation,
1965
- /* nameloc=*/ DeclNameLoc (),
1966
- /* Implicit=*/ true );
1967
- auto AppendInterpolationCall =
1968
- CallExpr::create (Context, AppendInterpolationRef,
1969
- lParen, args, argLabels, argLabelLocs, rParen,
1970
- /* trailingClosure=*/ nullptr , /* implicit=*/ false );
1971
-
1972
- Stmts.push_back (AppendInterpolationCall);
1916
+ Stmts.push_back (call);
1917
+ Status |= S;
1973
1918
1974
1919
if (!Tok.is (tok::eof)) {
1975
1920
diagnose (Tok, diag::string_interpolation_extra);
0 commit comments