mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[SE-0458] Disambiguate "unsafe" expression and for..in effect
Port over the disambiguation code we already had in the new Swift parser to the existing C++ parser for the "unsafe" expression and for..in effect.
This commit is contained in:
@@ -436,7 +436,9 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
|
||||
return sub;
|
||||
}
|
||||
|
||||
if (Tok.isContextualKeyword("unsafe")) {
|
||||
if (Tok.isContextualKeyword("unsafe") &&
|
||||
!peekToken().isAtStartOfLine() &&
|
||||
!peekToken().is(tok::r_paren)) {
|
||||
Tok.setKind(tok::contextual_keyword);
|
||||
SourceLoc unsafeLoc = consumeToken();
|
||||
ParserResult<Expr> sub =
|
||||
|
||||
@@ -2379,7 +2379,8 @@ ParserResult<Stmt> Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Tok.isContextualKeyword("unsafe")) {
|
||||
if (Tok.isContextualKeyword("unsafe") &&
|
||||
!peekToken().isAny(tok::colon, tok::kw_in)) {
|
||||
UnsafeLoc = consumeToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,15 @@ func testUnsafeAsSequenceForEach() {
|
||||
for unsafe _ in unsafe uas { } // okay
|
||||
}
|
||||
|
||||
func testForInUnsafeAmbiguity(_ integers: [Int]) {
|
||||
for unsafe in integers {
|
||||
_ = unsafe
|
||||
}
|
||||
for unsafe: Int in integers {
|
||||
_ = unsafe
|
||||
}
|
||||
}
|
||||
|
||||
struct UnsafeIterator: @unsafe IteratorProtocol {
|
||||
@unsafe mutating func next() -> Int? { nil }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user