Skip to content

Commit 8f83ca6

Browse files
committed
Parsing postfix exprs: if we have '.<keyword><code_complete>', try to recover
by creating an identifier with the same spelling as the keyword. Fixes code completion for cases like 'foo.is#^A^#'. Swift SVN r6727
1 parent 81a5a41 commit 8f83ca6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,27 @@ NullablePtr<Expr> Parser::parseExprPostfix(Diag<> ID) {
838838
}
839839
if (consumeIf(tok::period) || (IsPeriod && consumeIf(tok::period_prefix))) {
840840
if (Tok.isNot(tok::identifier) && Tok.isNot(tok::integer_literal)) {
841+
if (peekToken().is(tok::code_complete)) {
842+
switch (Tok.getKind()) {
843+
default:
844+
break;
845+
846+
#define KEYWORD(kw) \
847+
case tok::kw_##kw:
848+
#include "swift/Parse/Tokens.def"
849+
{
850+
// If we have a '.<keyword><code_complete>', then try to recover
851+
// by creating an identifier with the same spelling as the
852+
// keyword.
853+
Identifier Name = Context.getIdentifier(Tok.getText());
854+
Result = new (Context) UnresolvedDotExpr(Result.get(), TokLoc,
855+
Name, Tok.getLoc());
856+
consumeToken();
857+
}
858+
break;
859+
}
860+
}
861+
841862
if (Tok.is(tok::code_complete) && CodeCompletion && Result.isNonNull()) {
842863
CodeCompletion->completeDotExpr(Result.get());
843864
return nullptr;

0 commit comments

Comments
 (0)