Skip to content

Commit 056aed8

Browse files
committed
[Parser] Fix right angle location in erroneous parameter list
If '>' could not be found, the parser should return the location of the last token parsed, instead of the current token. Previously, it may causes ASTVerifier error "child source range not contained within its parent" in some cases.
1 parent 5494e82 commit 056aed8

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

lib/Parse/ParseGeneric.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,17 @@ Parser::parseGenericParameters(SourceLoc LAngleLoc) {
121121

122122
// Parse the closing '>'.
123123
SourceLoc RAngleLoc;
124-
if (!startsWithGreater(Tok)) {
124+
if (startsWithGreater(Tok)) {
125+
RAngleLoc = consumeStartingGreater();
126+
} else {
125127
if (!Invalid) {
126128
diagnose(Tok, diag::expected_rangle_generics_param);
127129
diagnose(LAngleLoc, diag::opening_angle);
128-
129130
Invalid = true;
130131
}
131-
132+
132133
// Skip until we hit the '>'.
133-
skipUntilGreaterInTypeList();
134-
if (startsWithGreater(Tok))
135-
RAngleLoc = consumeStartingGreater();
136-
else
137-
Invalid = true;
138-
} else {
139-
RAngleLoc = consumeStartingGreater();
134+
RAngleLoc = skipUntilGreaterInTypeList();
140135
}
141136

142137
if (GenericParams.empty() || Invalid) {

lib/Parse/Parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ void Parser::skipUntilAnyOperator() {
438438
/// of generic parameters, generic arguments, or list of types in a protocol
439439
/// composition.
440440
SourceLoc Parser::skipUntilGreaterInTypeList(bool protocolComposition) {
441-
SourceLoc lastLoc = Tok.getLoc();
441+
SourceLoc lastLoc = PreviousLoc;
442442
while (true) {
443443
switch (Tok.getKind()) {
444444
case tok::eof:
@@ -473,8 +473,8 @@ SourceLoc Parser::skipUntilGreaterInTypeList(bool protocolComposition) {
473473

474474
break;
475475
}
476-
lastLoc = Tok.getLoc();
477476
skipSingle();
477+
lastLoc = PreviousLoc;
478478
}
479479
}
480480

validation-test/compiler_crashers/28429-swift-decl-print.swift renamed to validation-test/compiler_crashers_fixed/28429-swift-decl-print.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// REQUIRES: asserts
1010
{class
1111
func g:protocol<

0 commit comments

Comments
 (0)