Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where switch case with multiple where clauses could parse incorrectly #1577

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

calda
Copy link
Collaborator

@calda calda commented Nov 10, 2023

This PR fixes an issue where switch cases with multiple where clauses could parse incorrectly. Fixes #1554.

Specifically, the < token in the example below was unexpectedly being tokenized as a .startOfScope token, leaving the : tokenized as a delimiter instead of a startOfScope. This broke the logic in switchStatementBranches, which was looking for a .startOfScope(":").

func foo(cases: FooCases, count: Int) -> String? {
  switch cases {
  case .fooCase1 where count == 0:
    return "foo"
  case .fooCase2 where count < 100,
       .fooCase3 where count < 100,
       .fooCase4:
    return "bar"
  default:
    return nil
  }
}

@@ -3266,26 +3266,6 @@ class TokenizerTests: XCTestCase {
XCTAssertEqual(tokenize(input), output)
}

func testGenericsWithWhereClause() {
let input = "<A where A.B == C>"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only test case that fails when I remove the case .keyword("where"): break logic. As far as I know this isn't valid Swift code -- I can't think of a case where the where keyword can appear in a generic <...> context. So it seems fine to just remove this to me.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was valid back in the Swift 2.0 era, but it's probably safe to drop support at this stage 😅

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Merging #1577 (e3e01a1) into develop (a22fbc3) will increase coverage by 0.48%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #1577      +/-   ##
===========================================
+ Coverage    95.03%   95.51%   +0.48%     
===========================================
  Files           20       20              
  Lines        21842    21840       -2     
===========================================
+ Hits         20757    20860     +103     
+ Misses        1085      980     -105     
Files Coverage Δ
Sources/Tokenizer.swift 96.54% <ø> (-0.01%) ⬇️

... and 3 files with indirect coverage changes

@nicklockwood nicklockwood merged commit f2e8702 into nicklockwood:develop Nov 10, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants