Skip to content

Parse: Fix capture list parsing with 'self' #11263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ parseClosureSignatureIfPresent(SmallVectorImpl<CaptureListEntry> &captureList,
if (!consumeIf(tok::r_paren))
diagnose(Tok, diag::attr_unowned_expected_rparen);
}
} else if (Tok.is(tok::identifier) &&
} else if (Tok.isAny(tok::identifier, tok::kw_self) &&
peekToken().isAny(tok::equal, tok::comma, tok::r_square)) {
// "x = 42", "x," and "x]" are all strong captures of x.
loc = Tok.getLoc();
Expand Down
7 changes: 7 additions & 0 deletions test/Sema/diag_invalid_inout_captures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ struct you_cry_in_your_tea {
mutating func which_you_hurl_in_the_sea_when_you_see_me_go_by() {
no_escape { _ = self } // OK
do_escape { _ = self } // expected-error {{closure cannot implicitly capture a mutating self parameter}}
do_escape {
[self] in
_ = self // OK
self.other_mutator() // expected-error {{cannot use mutating member on immutable value: 'self' is an immutable capture}}
}
}

mutating func other_mutator() {}
}

func why_so_sad(line: inout String) {
Expand Down