File tree Expand file tree Collapse file tree 2 files changed +25
-10
lines changed
Tests/SwiftParserTest/translated Expand file tree Collapse file tree 2 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -504,16 +504,16 @@ extension Parser {
504
504
505
505
case ( . consumeKeyword, let handle) ? :
506
506
// `consume` is only contextually a keyword, if it's followed by an
507
- // identifier or keyword on the same line.
508
- let next = peek ( )
509
- if next. isAtStartOfLine {
510
- break
511
- }
512
- if next. rawTokenKind != . identifier,
513
- next. rawTokenKind != . dollarIdentifier,
514
- next. rawTokenKind != . keyword
515
- {
507
+ // identifier or keyword on the same line. We do this to ensure that we do
508
+ // not break any copy functions defined by users. This is following with
509
+ // what we have done for the consume keyword.
510
+ switch self . peek ( ) {
511
+ case TokenSpec ( . identifier, allowAtStartOfLine: false ) ,
512
+ TokenSpec ( . dollarIdentifier, allowAtStartOfLine: false ) ,
513
+ TokenSpec ( . self , allowAtStartOfLine: false ) :
516
514
break
515
+ default :
516
+ break EXPR_PREFIX // break out of the outer `switch`
517
517
}
518
518
519
519
let consumeTok = self . eat ( handle)
Original file line number Diff line number Diff line change @@ -82,5 +82,20 @@ final class MoveExprTests: XCTestCase {
82
82
"""
83
83
)
84
84
}
85
- } }
85
+
86
+ func testConsumeVariableNameInCast( ) {
87
+ assertParse (
88
+ """
89
+ class ParentKlass {}
90
+ class SubKlass : ParentKlass {}
91
+
92
+ func test(_ x: SubKlass) {
93
+ switch x {
94
+ case let consume as ParentKlass:
95
+ fallthrough
96
+ }
97
+ }
98
+ """ )
99
+ }
100
+ }
86
101
You can’t perform that action at this time.
0 commit comments