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 c4c193d
Showing 1 changed file with 5 additions and 5 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

0 comments on commit c4c193d

Please sign in to comment.