nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.87k stars 637 forks source link

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

Closed calda closed 11 months ago

calda commented 11 months ago

This PR fixes an issue where switch cases with multiple where clauses could parse incorrectly. Fixes https://github.com/nicklockwood/SwiftFormat/issues/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
  }
}
codecov[bot] commented 11 months ago

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%) :arrow_down:

... and 3 files with indirect coverage changes