Skip to content

Commit

Permalink
Router: binpack defn single-line to avoid overflow
Browse files Browse the repository at this point in the history
The current rule could occasionally lead to overflow since it didn't use
a killall (remove path on failure) optimal token, and then would arrive
at a point where other viable alternatives would have been set aside.
  • Loading branch information
kitbellew committed Dec 28, 2021
1 parent 4054630 commit d527e84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1101,9 +1101,9 @@ class Router(formatOps: FormatOps) {
val mustDangle = onlyConfigStyle ||
style.danglingParentheses.defnSite &&
(style.newlines.sourceIgnored || !style.optIn.configStyleArguments)
val slbOnly = mustDangle || style.newlines.source.eq(Newlines.unfold)
def noSplitPolicy: Policy =
if (mustDangle || style.newlines.source.eq(Newlines.unfold))
slbPolicy
if (slbOnly) slbPolicy
else {
val penalizeOpens = bracketPenalty.fold(Policy.noPolicy) { p =>
Policy.before(close) {
Expand Down Expand Up @@ -1132,11 +1132,11 @@ class Router(formatOps: FormatOps) {
def nlCost = bracketPenalty.getOrElse(1)

Seq(
Split(noSplitModification, 0)
.notIf(mustUseNL)
Split(mustUseNL, 0)(noSplitModification)
.withOptimalToken(close, ignore = !slbOnly, killOnFail = true)
.withPolicy(noSplitPolicy)
.withIndents(noSplitIndents),
Split(nlMod, if (mustUseNL) 0 else nlCost)
Split(nlMod, if (mustUseNL || slbOnly) 0 else nlCost)
.withPolicy(nlDanglePolicy & onelinePolicy & penalizeBrackets)
.withIndent(indent)
)
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4382,9 +4382,9 @@ object a {
}
>>>
object a {
def foo(
bb: BB, cc: CC, dd: DD = DDD.ddd
): Bar[Baz] = {
def foo(bb: BB, cc: CC, dd: DD = DDD.ddd): Bar[
Baz
] = {
// c
qux
}
Expand Down
6 changes: 3 additions & 3 deletions scalafmt-tests/src/test/resources/newlines/source_unfold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -4807,9 +4807,9 @@ object a {
}
>>>
object a {
def foo(
bb: BB, cc: CC, dd: DD = DDD.ddd
): Bar[Baz] = {
def foo(bb: BB, cc: CC, dd: DD = DDD.ddd): Bar[
Baz
] = {
// c
qux
}
Expand Down

0 comments on commit d527e84

Please sign in to comment.