Skip to content

Commit

Permalink
Router: extend optimal token to include comment
Browse files Browse the repository at this point in the history
Fixes non-idempotence and incorrect handling of avoidForSimpleOverflow
containing only `tooLong` (which applies only when there's no possible
alternative which doesn't overflow).
  • Loading branch information
kitbellew committed Aug 6, 2024
1 parent 482ecbd commit 038cae5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2529,9 +2529,7 @@ class Router(formatOps: FormatOps) {
case _: Term.ForYield => twoBranches
// we force newlines in try/catch/finally
case _: Term.Try | _: Term.TryWithHandler => Split.ignored
case t: Term.Apply if t.argClause.nonEmpty =>
baseSpaceSplit.withOptimalToken(optimalWithComment)
case _ => baseSpaceSplit.withOptimalToken(optimal)
case _ => baseSpaceSplit.withOptimalToken(optimalWithComment)
}
Seq(
spaceSplit,
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ override final def next(): To =
override final def next(): To =
if (hasNext) {
val ret = _next
_next =
null.asInstanceOf[To] // Mark as consumed aaaaaaaaaaaaaaaaaa(nice to the GC, don't leak the last returned value)
_next = null
.asInstanceOf[To] // Mark as consumed aaaaaaaaaaaaaaaaaa(nice to the GC, don't leak the last returned value)
_hasNext = false // Mark as consumed (we need to look for the next value)
ret
} else throw new java.util.NoSuchElementException("next")
Expand Down
6 changes: 4 additions & 2 deletions scalafmt-tests/src/test/resources/default/String.stat
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ object a {
>>>
object a {
intercept[TestException] {
val ct = Thread.currentThread() // Ensure that the thunk is executed in the tests thread
val ct = Thread
.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 2.2 don't break, overflows anyway
Expand Down Expand Up @@ -233,7 +234,8 @@ object a {
>>>
object a {
intercept[TestException] {
val ct = Thread.currentThread() // Ensure that the thunk is executed in the tests thread
val ct = Thread
.currentThread() // Ensure that the thunk is executed in the tests thread
}
}
<<< #1505 4
Expand Down
15 changes: 5 additions & 10 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -2002,16 +2002,11 @@ object a:
def foo =
bar = baz + baz(qux) // c1
>>>
Idempotency violated
=> Diff (- obtained, + expected)
def foo =
- bar = baz + baz(
- qux
- ) // c1
+ bar =
+ baz + baz(
+ qux
+ ) // c1
object a:
def foo =
bar = baz + baz(
qux
) // c1
<<< #2561 no forced dangle in tuples
maxColumn = 40
newlines {
Expand Down

0 comments on commit 038cae5

Please sign in to comment.