File tree Expand file tree Collapse file tree 3 files changed +53
-3
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 3 files changed +53
-3
lines changed Original file line number Diff line number Diff line change @@ -465,7 +465,7 @@ extension Parser {
465
465
}
466
466
467
467
precondition ( self . currentToken. starts ( with: " < " ) )
468
- let langle = self . consumeAnyToken ( remapping : . leftAngle)
468
+ let langle = self . consumeStartingCharacterOfCurrentToken ( as : . leftAngle)
469
469
var elements = [ RawGenericParameterSyntax] ( )
470
470
do {
471
471
var keepGoing : RawTokenSyntax ? = nil
@@ -477,7 +477,7 @@ extension Parser {
477
477
var each = self . consume ( if: . keyword( . each) )
478
478
479
479
let ( unexpectedBetweenEachAndName, name) = self . expectIdentifier ( allowSelfOrCapitalSelfAsIdentifier: true )
480
- if attributes == nil && each == nil && unexpectedBetweenEachAndName == nil && name. isMissing && elements. isEmpty {
480
+ if attributes == nil && each == nil && unexpectedBetweenEachAndName == nil && name. isMissing && elements. isEmpty && ! self . currentToken . starts ( with : " > " ) {
481
481
break
482
482
}
483
483
Original file line number Diff line number Diff line change @@ -557,6 +557,37 @@ extension Parser {
557
557
)
558
558
return tok
559
559
}
560
+
561
+ /// Consumes a single token and advances the current token by 1.
562
+ mutating func consumeStartingCharacterOfCurrentToken(
563
+ as tokenKind: RawTokenKind
564
+ ) -> RawTokenSyntax {
565
+ let current = self . currentToken
566
+
567
+ let endIndex = current. textRange. lowerBound. advanced ( by: 1 )
568
+ var tokenDiagnostic = current. diagnostic
569
+ if let error = tokenDiagnostic, error. byteOffset > current. leadingTriviaByteLength + 1 {
570
+ // The lexer error isn't in the prefix. Drop it.
571
+ tokenDiagnostic = nil
572
+ }
573
+
574
+ let tok = RawTokenSyntax (
575
+ kind: tokenKind,
576
+ wholeText: SyntaxText ( rebasing: current. wholeText [ ..< endIndex] ) ,
577
+ textRange: current. textRange. lowerBound..< endIndex,
578
+ presence: . present,
579
+ tokenDiagnostic: tokenDiagnostic,
580
+ arena: self . arena
581
+ )
582
+
583
+ self . adjustNestingLevel ( for: tokenKind)
584
+
585
+ self . currentToken = self . lexemes. resetForSplit (
586
+ splitToken: self . currentToken,
587
+ consumedPrefix: self . currentToken. leadingTriviaByteLength + 1
588
+ )
589
+ return tok
590
+ }
560
591
}
561
592
562
593
extension SyntaxText {
Original file line number Diff line number Diff line change @@ -1031,7 +1031,7 @@ final class RecoveryTests: XCTestCase {
1031
1031
assertParse (
1032
1032
"""
1033
1033
// Note: Don't move braces to a different line here.
1034
- struct ErrorGenericParameterList4< 1️⃣
1034
+ struct ErrorGenericParameterList4<1️⃣
1035
1035
{
1036
1036
}
1037
1037
""" ,
@@ -2245,4 +2245,23 @@ final class RecoveryTests: XCTestCase {
2245
2245
)
2246
2246
}
2247
2247
2248
+ // https://github.com/apple/swift-syntax/issues/1483
2249
+ func testRecovery183( ) {
2250
+ // Can be parsed and produces no diagnostics.
2251
+ assertParse (
2252
+ " func f<1️⃣ >() {} " ,
2253
+ diagnostics: [
2254
+ DiagnosticSpec ( message: " expected generic parameter in generic parameter clause " )
2255
+ ]
2256
+ )
2257
+
2258
+ // Can be parsed. Printing the node or asking for the diagnostics leads to a crash.
2259
+ assertParse (
2260
+ " func f<1️⃣>() {} " ,
2261
+ diagnostics: [
2262
+ DiagnosticSpec ( message: " expected generic parameter in generic parameter clause " )
2263
+ ]
2264
+ )
2265
+ }
2266
+
2248
2267
}
You can’t perform that action at this time.
0 commit comments