Skip to content

Commit b337552

Browse files
committed
[Parse] Tighten constraints in canParseNonisolatedAsTypeModifier
Accept it only if it's spelled `nonisolated(nonsending)` and nothing else to minimize any possible source compatibility impact.
1 parent 72500a9 commit b337552

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/Parse/ParseType.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,17 +1749,19 @@ bool Parser::canParseNonisolatedAsTypeModifier() {
17491749
if (Tok.isAtStartOfLine())
17501750
return false;
17511751

1752-
// Always requires `(<<argument>>)`
1753-
if (!Tok.is(tok::l_paren))
1752+
// Always requires `(nonsending)`, together
1753+
// we don't want eagerly interpret something
1754+
// like `nonisolated(0)` as a modifier.
1755+
1756+
if (!consumeIf(tok::l_paren))
17541757
return false;
17551758

1756-
// Consume argument list
1757-
skipSingle();
1759+
if (!Tok.isContextualKeyword("nonsending"))
1760+
return false;
17581761

1759-
// if consumed '(...)' ended up being followed
1760-
// by `[async, throws, ...] -> ...` this means
1761-
// the `nonisolated` is invalid as a modifier.
1762-
return !isAtFunctionTypeArrow();
1762+
consumeToken();
1763+
1764+
return consumeIf(tok::r_paren);
17631765
}
17641766

17651767
bool Parser::canParseTypeScalar() {

test/Parse/execution_behavior_attrs.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ do {
7777

7878
_ = [nonisolated()]
7979
}
80+
81+
do {
82+
func nonisolated(_: Int) -> Int { 42 }
83+
84+
nonisolated(0) // expected-warning {{result of call to 'nonisolated' is unused}}
85+
print("hello")
86+
}

0 commit comments

Comments
 (0)