mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SE-0458: Disambiguate postfix expressions vs. unsafe expressions more generally
Handle call-vs-tuple and subscript-vs-collection-expr disambiguation using the same "no trivia" rule that we used to disambiguite "unsafe.x" (which we treat as a member access) from "unsafe .x" (which we treat as an unsafe expression with a leading-dot member access). Fixes rdar://146459104.
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -183,6 +183,8 @@ func acceptBools(_: Bool, _: Bool) { }
|
||||
|
||||
func acceptBoolsUnsafeLabel(unsafe _: Bool, _: Bool) { }
|
||||
|
||||
func unsafe(_: Int) { }
|
||||
|
||||
func unsafeFun() {
|
||||
var unsafe = true
|
||||
unsafe = false
|
||||
@@ -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>(
|
||||
|
||||
Reference in New Issue
Block a user