Skip to content

Commit c3c5a55

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 826176a commit c3c5a55

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
@@ -1747,17 +1747,19 @@ bool Parser::canParseNonisolatedAsTypeModifier() {
17471747
if (Tok.isAtStartOfLine())
17481748
return false;
17491749

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

1754-
// Consume argument list
1755-
skipSingle();
1757+
if (!Tok.isContextualKeyword("nonsending"))
1758+
return false;
17561759

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

17631765
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)