Skip to content

Commit 6e20af9

Browse files
rintarorjmccall
authored andcommitted
[Parse] Parse editor placeholder as a labeled trailng closure
So that SourceKit can expand them to closure literals.
1 parent 78209e2 commit 6e20af9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,6 +3163,11 @@ static bool isStartOfLabelledTrailingClosure(Parser &P) {
31633163
P.consumeToken();
31643164
if (P.peekToken().is(tok::l_brace))
31653165
return true;
3166+
// Parse editor placeholder as trailing closure so SourceKit can expand it to
3167+
// closure literal.
3168+
if (P.peekToken().is(tok::identifier) &&
3169+
Identifier::isEditorPlaceholder(P.peekToken().getText()))
3170+
return true;
31663171
// Consider `label: <complete>` that the user is trying to write a closure.
31673172
if (P.peekToken().is(tok::code_complete) && !P.peekToken().isAtStartOfLine())
31683173
return true;
@@ -3230,6 +3235,14 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32303235
ParserResult<Expr> closure;
32313236
if (Tok.is(tok::l_brace)) {
32323237
closure = parseExprClosure();
3238+
} else if (Tok.is(tok::identifier)) {
3239+
// Parse editor placeholder as a closure literal.
3240+
assert(Identifier::isEditorPlaceholder(Tok.getText()));
3241+
SyntaxParsingContext IdCtx(SyntaxContext,
3242+
SyntaxKind::EditorPlaceholderExpr);
3243+
Identifier name = Context.getIdentifier(Tok.getText());
3244+
closure = makeParserResult(parseExprEditorPlaceholder(Tok, name));
3245+
consumeToken(tok::identifier);
32333246
} else if (Tok.is(tok::code_complete)) {
32343247
assert(!Tok.isAtStartOfLine() &&
32353248
"isStartOfLabelledTrailingClosure() should return false");

test/Parse/multiple_trailing_closures.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ func test_multiple_trailing_syntax_without_labels() {
8484

8585
fn {} _: {} // expected-error {{extra argument in call}}
8686

87+
fn {} g: <#T##() -> Void#> // expected-error {{editor placeholder in source file}}
88+
8789
func multiple(_: () -> Void, _: () -> Void) {}
8890

8991
multiple {} _: { }

0 commit comments

Comments
 (0)