Skip to content

Commit 0355a87

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 c0bf473 commit 0355a87

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
@@ -3159,6 +3159,11 @@ static bool isStartOfLabelledTrailingClosure(Parser &P) {
31593159
P.consumeToken();
31603160
if (P.peekToken().is(tok::l_brace))
31613161
return true;
3162+
// Parse editor placeholder as trailing closure so SourceKit can expand it to
3163+
// closure literal.
3164+
if (P.peekToken().is(tok::identifier) &&
3165+
Identifier::isEditorPlaceholder(P.peekToken().getText()))
3166+
return true;
31623167
// Consider `label: <complete>` that the user is trying to write a closure.
31633168
if (P.peekToken().is(tok::code_complete) && !P.peekToken().isAtStartOfLine())
31643169
return true;
@@ -3226,6 +3231,14 @@ Parser::parseTrailingClosures(bool isExprBasic, SourceRange calleeRange,
32263231
ParserResult<Expr> closure;
32273232
if (Tok.is(tok::l_brace)) {
32283233
closure = parseExprClosure();
3234+
} else if (Tok.is(tok::identifier)) {
3235+
// Parse editor placeholder as a closure literal.
3236+
assert(Identifier::isEditorPlaceholder(Tok.getText()));
3237+
SyntaxParsingContext IdCtx(SyntaxContext,
3238+
SyntaxKind::EditorPlaceholderExpr);
3239+
Identifier name = Context.getIdentifier(Tok.getText());
3240+
closure = makeParserResult(parseExprEditorPlaceholder(Tok, name));
3241+
consumeToken(tok::identifier);
32293242
} else if (Tok.is(tok::code_complete)) {
32303243
assert(!Tok.isAtStartOfLine() &&
32313244
"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)