Skip to content

Commit b038376

Browse files
authored
Merge pull request swiftlang#79842 from DougGregor/se-0458-postfix-disambig
2 parents e5487d8 + 6cf56e9 commit b038376

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Parse/ParseExpr.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
441441
peekToken().isAny(tok::r_paren, tok::r_brace, tok::r_square,
442442
tok::equal, tok::colon, tok::comma) ||
443443
(isExprBasic && peekToken().is(tok::l_brace)) ||
444-
peekToken().is(tok::period))) {
444+
peekToken().is(tok::period) ||
445+
(peekToken().isAny(tok::l_paren, tok::l_square) &&
446+
peekToken().getRange().getStart() == Tok.getRange().getEnd()))) {
445447
Tok.setKind(tok::contextual_keyword);
446448
SourceLoc unsafeLoc = consumeToken();
447449
ParserResult<Expr> sub =

test/Unsafe/safe.swift

+16
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ func acceptBools(_: Bool, _: Bool) { }
183183

184184
func acceptBoolsUnsafeLabel(unsafe _: Bool, _: Bool) { }
185185

186+
func unsafe(_: Int) { }
187+
186188
func unsafeFun() {
187189
var unsafe = true
188190
unsafe = false
@@ -200,6 +202,20 @@ func unsafeFun() {
200202
if unsafe { }
201203
}
202204

205+
func moreUnsafeFunc(unsafe: [Int]) {
206+
let _: [Int] = unsafe []
207+
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}
208+
209+
_ = unsafe[1]
210+
}
211+
212+
func yetMoreUnsafeFunc(unsafe: () -> Void) {
213+
unsafe()
214+
215+
_ = unsafe ()
216+
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}
217+
}
218+
203219
// @safe suppresses unsafe-type-related diagnostics on an entity
204220
struct MyArray<Element> {
205221
@safe func withUnsafeBufferPointer<R, E>(

0 commit comments

Comments
 (0)