From b9cb5ce7914f3f5ebdb743a21916b2a7b6d6ffdd Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 7 Mar 2025 15:07:45 -0800 Subject: [PATCH] [SE-0458] Disambiguate "unsafe" expression within string interpolation String interpolation uses an end-of-file token, which we weren't checking for. Fixes rdar://146493296 --- lib/Parse/ParseExpr.cpp | 2 +- test/Unsafe/safe.swift | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index d3fbc3a614ffc..6acbde2a188c4 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -439,7 +439,7 @@ ParserResult Parser::parseExprSequenceElement(Diag<> message, if (Tok.isContextualKeyword("unsafe") && !(peekToken().isAtStartOfLine() || peekToken().isAny(tok::r_paren, tok::r_brace, tok::r_square, - tok::equal, tok::colon, tok::comma) || + tok::equal, tok::colon, tok::comma, tok::eof) || (isExprBasic && peekToken().is(tok::l_brace)) || peekToken().is(tok::period) || (peekToken().isAny(tok::l_paren, tok::l_square) && diff --git a/test/Unsafe/safe.swift b/test/Unsafe/safe.swift index e2e80ccd00c8f..90271a9bca1b6 100644 --- a/test/Unsafe/safe.swift +++ b/test/Unsafe/safe.swift @@ -207,6 +207,8 @@ func moreUnsafeFunc(unsafe: [Int]) { // expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}} _ = unsafe[1] + + _ = "\(unsafe)" } func yetMoreUnsafeFunc(unsafe: () -> Void) {