Skip to content

Commit c79bb32

Browse files
committed
parsePattern(): try harder to recover. Fixes a code completion test case
Swift SVN r7397
1 parent aefbf9d commit c79bb32

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,27 @@ Parser::parseFunctionSignature(SmallVectorImpl<Pattern *> &argPatterns,
289289
/// pattern ::= pattern-atom ':' type-annotation
290290
ParserResult<Pattern> Parser::parsePattern() {
291291
// First, parse the pattern atom.
292-
ParserResult<Pattern> pattern = parsePatternAtom();
293-
if (pattern.isNull())
294-
return nullptr;
292+
ParserResult<Pattern> Result = parsePatternAtom();
295293

296294
// Now parse an optional type annotation.
297295
if (consumeIf(tok::colon)) {
296+
if (Result.isNull()) {
297+
// Recover by creating AnyPattern.
298+
Result = makeParserErrorResult(new (Context) AnyPattern(Tok.getLoc()));
299+
}
300+
298301
ParserResult<TypeRepr> Ty = parseTypeAnnotation();
299302
if (Ty.hasCodeCompletion())
300303
return makeParserCodeCompletionResult<Pattern>();
301304

302305
if (Ty.isNull())
303306
Ty = makeParserResult(new (Context) ErrorTypeRepr(Tok.getLoc()));
304307

305-
pattern = makeParserResult(
306-
new (Context) TypedPattern(pattern.get(), Ty.get()));
308+
Result = makeParserResult(Result,
309+
new (Context) TypedPattern(Result.get(), Ty.get()));
307310
}
308311

309-
return pattern;
312+
return Result;
310313
}
311314

312315
/// \brief Determine whether this token can start a pattern.

0 commit comments

Comments
 (0)