mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
More disambiguation for "unsafe" expressions
Fixes rdar://145870868 / #79704
This commit is contained in:
@@ -437,8 +437,10 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
|
||||
}
|
||||
|
||||
if (Tok.isContextualKeyword("unsafe") &&
|
||||
!peekToken().isAtStartOfLine() &&
|
||||
!peekToken().is(tok::r_paren)) {
|
||||
!(peekToken().isAtStartOfLine() ||
|
||||
peekToken().isAny(tok::r_paren, tok::r_brace, tok::r_square,
|
||||
tok::equal) ||
|
||||
peekToken().is(tok::period))) {
|
||||
Tok.setKind(tok::contextual_keyword);
|
||||
SourceLoc unsafeLoc = consumeToken();
|
||||
ParserResult<Expr> sub =
|
||||
|
||||
@@ -175,6 +175,23 @@ func testUnsafePositionError() -> Int {
|
||||
return 3 + unsafe unsafeInt() // expected-error{{'unsafe' cannot appear to the right of a non-assignment operator}}
|
||||
}
|
||||
|
||||
enum Color {
|
||||
case red
|
||||
}
|
||||
|
||||
func unsafeFun() {
|
||||
var unsafe = true
|
||||
unsafe = false
|
||||
unsafe.toggle()
|
||||
_ = [unsafe]
|
||||
_ = { unsafe }
|
||||
|
||||
let color: Color
|
||||
// expected-warning@+1{{no unsafe operations occur within 'unsafe' expression}}
|
||||
color = unsafe .red
|
||||
_ = color
|
||||
}
|
||||
|
||||
// @safe suppresses unsafe-type-related diagnostics on an entity
|
||||
struct MyArray<Element> {
|
||||
@safe func withUnsafeBufferPointer<R, E>(
|
||||
|
||||
Reference in New Issue
Block a user