File tree Expand file tree Collapse file tree
Tests/SwiftParserTest/translated Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -504,16 +504,16 @@ extension Parser {
504504
505505 case ( . consumeKeyword, let handle) ? :
506506 // `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 ) :
516514 break
515+ default :
516+ break EXPR_PREFIX // break out of the outer `switch`
517517 }
518518
519519 let consumeTok = self . eat ( handle)
Original file line number Diff line number Diff line change @@ -82,5 +82,20 @@ final class MoveExprTests: XCTestCase {
8282 """
8383 )
8484 }
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+ }
86101
You can’t perform that action at this time.
0 commit comments