Skip to content

Commit 7161ed0

Browse files
committed
Work Around IDE Structure Markers
Structure analysis trusts what should be implicit pattern nodes have the right source location information in them. Preserve that behavior for now.
1 parent 72807bf commit 7161ed0

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,14 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
887887
SyntaxParsingContext TypeAnnoCtx(SyntaxContext, SyntaxKind::TypeAnnotation);
888888
SourceLoc colonLoc = consumeToken(tok::colon);
889889

890-
if (result.isNull()) // Recover by creating AnyPattern.
891-
result = makeParserErrorResult(new (Context) AnyPattern(colonLoc));
892-
890+
if (result.isNull()) {
891+
// Recover by creating AnyPattern.
892+
auto *AP = new (Context) AnyPattern(colonLoc);
893+
if (colonLoc.isInvalid())
894+
AP->setImplicit();
895+
result = makeParserErrorResult(AP);
896+
}
897+
893898
ParserResult<TypeRepr> Ty = parseDeclResultType(diag::expected_type);
894899
if (Ty.hasCodeCompletion())
895900
return makeParserCodeCompletionResult<Pattern>();

lib/Parse/ParseStmt.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,12 @@ static void parseGuardedPattern(Parser &P, GuardedPattern &result,
11081108

11091109
// If that didn't work, use a bogus pattern so that we can fill out
11101110
// the AST.
1111-
if (patternResult.isNull())
1112-
patternResult =
1113-
makeParserErrorResult(new (P.Context) AnyPattern(P.PreviousLoc));
1111+
if (patternResult.isNull()) {
1112+
auto *AP = new (P.Context) AnyPattern(P.PreviousLoc);
1113+
if (P.PreviousLoc.isInvalid())
1114+
AP->setImplicit();
1115+
patternResult = makeParserErrorResult(AP);
1116+
}
11141117

11151118
// Fill in the pattern.
11161119
status |= patternResult;
@@ -1506,7 +1509,10 @@ Parser::parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,
15061509

15071510
if (ThePattern.isNull()) {
15081511
// Recover by creating AnyPattern.
1509-
ThePattern = makeParserResult(new (Context) AnyPattern(PreviousLoc));
1512+
auto *AP = new (Context) AnyPattern(PreviousLoc);
1513+
if (PreviousLoc.isInvalid())
1514+
AP->setImplicit();
1515+
ThePattern = makeParserResult(AP);
15101516
}
15111517

15121518
// Conditional bindings must have an initializer.
@@ -2133,7 +2139,7 @@ ParserResult<Stmt> Parser::parseStmtForEach(LabeledStmtInfo LabelInfo) {
21332139
SourceLoc InLoc;
21342140
if (pattern.isNull()) {
21352141
// Recover by creating a "_" pattern.
2136-
pattern = makeParserErrorResult(new (Context) AnyPattern(SourceLoc()));
2142+
pattern = makeParserErrorResult(AnyPattern::createImplicit(Context));
21372143
consumeIf(tok::kw_in, InLoc);
21382144
} else if (!IsCStyleFor) {
21392145
parseToken(tok::kw_in, InLoc, diag::expected_foreach_in);
@@ -2422,6 +2428,8 @@ parseStmtCaseDefault(Parser &P, SourceLoc &CaseLoc,
24222428

24232429
// Create an implicit AnyPattern to represent the default match.
24242430
auto Any = new (P.Context) AnyPattern(CaseLoc);
2431+
if (CaseLoc.isInvalid())
2432+
Any->setImplicit();
24252433
LabelItems.push_back(
24262434
CaseLabelItem::getDefault(Any, WhereLoc, Guard.getPtrOrNull()));
24272435

0 commit comments

Comments
 (0)