Skip to content

Commit a870e25

Browse files
authored
Merge pull request #79771 from DougGregor/more-unsafe-disambig
2 parents 6f132fd + be7e875 commit a870e25

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Parse/ParseExpr.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
439439
if (Tok.isContextualKeyword("unsafe") &&
440440
!(peekToken().isAtStartOfLine() ||
441441
peekToken().isAny(tok::r_paren, tok::r_brace, tok::r_square,
442-
tok::equal) ||
442+
tok::equal, tok::colon, tok::comma) ||
443+
(isExprBasic && peekToken().is(tok::l_brace)) ||
443444
peekToken().is(tok::period))) {
444445
Tok.setKind(tok::contextual_keyword);
445446
SourceLoc unsafeLoc = consumeToken();

test/Unsafe/safe.swift

+8
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,25 @@ enum Color {
179179
case red
180180
}
181181

182+
func acceptBools(_: Bool, _: Bool) { }
183+
184+
func acceptBoolsUnsafeLabel(unsafe _: Bool, _: Bool) { }
185+
182186
func unsafeFun() {
183187
var unsafe = true
184188
unsafe = false
185189
unsafe.toggle()
186190
_ = [unsafe]
187191
_ = { unsafe }
192+
acceptBools(unsafe, unsafe)
193+
acceptBoolsUnsafeLabel(unsafe: unsafe, unsafe)
188194

189195
let color: Color
190196
// expected-warning@+1{{no unsafe operations occur within 'unsafe' expression}}
191197
color = unsafe .red
192198
_ = color
199+
200+
if unsafe { }
193201
}
194202

195203
// @safe suppresses unsafe-type-related diagnostics on an entity

0 commit comments

Comments
 (0)