Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
peekToken().isAny(tok::r_paren, tok::r_brace, tok::r_square,
tok::equal, tok::colon, tok::comma) ||
(isExprBasic && peekToken().is(tok::l_brace)) ||
peekToken().is(tok::period))) {
peekToken().is(tok::period) ||
(peekToken().isAny(tok::l_paren, tok::l_square) &&
peekToken().getRange().getStart() == Tok.getRange().getEnd()))) {
Tok.setKind(tok::contextual_keyword);
SourceLoc unsafeLoc = consumeToken();
ParserResult<Expr> sub =
Expand Down
16 changes: 16 additions & 0 deletions test/Unsafe/safe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ func acceptBools(_: Bool, _: Bool) { }

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

func unsafe(_: Int) { }

func unsafeFun() {
var unsafe = true
unsafe = false
Expand All @@ -200,6 +202,20 @@ func unsafeFun() {
if unsafe { }
}

func moreUnsafeFunc(unsafe: [Int]) {
let _: [Int] = unsafe []
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}

_ = unsafe[1]
}

func yetMoreUnsafeFunc(unsafe: () -> Void) {
unsafe()

_ = unsafe ()
// expected-warning@-1{{no unsafe operations occur within 'unsafe' expression}}
}

// @safe suppresses unsafe-type-related diagnostics on an entity
struct MyArray<Element> {
@safe func withUnsafeBufferPointer<R, E>(
Expand Down