Skip to content

Commit 431d5e6

Browse files
authored
Merge pull request #11263 from slavapestov/capture-list-fix
Parse: Fix capture list parsing with 'self'
2 parents a24a439 + f93447e commit 431d5e6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
22792279
if (!consumeIf(tok::r_paren))
22802280
diagnose(Tok, diag::attr_unowned_expected_rparen);
22812281
}
2282-
} else if (Tok.is(tok::identifier) &&
2282+
} else if (Tok.isAny(tok::identifier, tok::kw_self) &&
22832283
peekToken().isAny(tok::equal, tok::comma, tok::r_square)) {
22842284
// "x = 42", "x," and "x]" are all strong captures of x.
22852285
loc = Tok.getLoc();

test/Sema/diag_invalid_inout_captures.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ struct you_cry_in_your_tea {
77
mutating func which_you_hurl_in_the_sea_when_you_see_me_go_by() {
88
no_escape { _ = self } // OK
99
do_escape { _ = self } // expected-error {{closure cannot implicitly capture a mutating self parameter}}
10+
do_escape {
11+
[self] in
12+
_ = self // OK
13+
self.other_mutator() // expected-error {{cannot use mutating member on immutable value: 'self' is an immutable capture}}
14+
}
1015
}
16+
17+
mutating func other_mutator() {}
1118
}
1219

1320
func why_so_sad(line: inout String) {

0 commit comments

Comments
 (0)