Skip to content

Commit

Permalink
FormatOps: unfold yield correctly and consistently
Browse files Browse the repository at this point in the history
We were handling it differently in some cases, and inconsistent with
`while` and other `for`.
  • Loading branch information
kitbellew committed Jan 10, 2022
1 parent ce64bed commit 6defa06
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1745,14 +1745,8 @@ class FormatOps(
def slbSplit(end: T)(implicit fileLine: FileLine) =
Split(Space, 0).withSingleLine(end, noSyntaxNL = true)
body match {
case _: Term.ForYield =>
// unfold policy on yield forces a break
// revert it if we are attempting a single line
val noBreakOnYield = Policy.before(expire) {
case Decision(ft, s) if s.isEmpty && ft.right.is[T.KwYield] =>
Seq(Split(Space, 0))
}
slbSplit(expire).andPolicy(noBreakOnYield)
// we force newlines in for/yield
case _: Term.ForYield => Split.ignored
// we force newlines in try/catch/finally
case _: Term.Try | _: Term.TryWithHandler => Split.ignored
// don't tuck curried apply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,9 @@ maxColumn = 80
val attributes =
for (i ← 1 to count) yield i
>>>
val attributes = for (i ← 1 to count) yield i
val attributes =
for (i ← 1 to count)
yield i
<<< 2.14 val with short for/do
maxColumn = 80
===
Expand Down

0 comments on commit 6defa06

Please sign in to comment.