diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 8911a513d..b487336db 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1387,7 +1387,7 @@ class FormatOps( ok && (thisTree match { case _: Term.Match => // like select and apply in one - !tokenAfter(thisSelectLike.nameToken).right.is[T.LeftBrace] || + !tokenAfter(thisSelectLike.nameFt).right.is[T.LeftBrace] || style.includeCurlyBraceInSelectChains && nextSelect.isDefined && !nextSelect.contains(lastApply) case _ => checkParent diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 4a8c2746b..1a9efcaf6 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -1803,7 +1803,7 @@ class Router(formatOps: FormatOps) { } val nextDotIfSig = nextSelect.flatMap { ns => val ok = checkFewerBraces(ns.qual) - if (ok) Some(tokenBefore(ns.nameToken)) else None + if (ok) Some(tokenBefore(ns.nameFt)) else None } def forcedBreakOnNextDotPolicy = nextSelect.map { selectLike => val tree = selectLike.tree @@ -1959,8 +1959,9 @@ class Router(formatOps: FormatOps) { if (nextDotIfSig.isEmpty) if (nlOnly) Seq(nlSplitBase(0)) else { - val end = nextSelect - .fold(expire)(x => getLastNonTrivialToken(x.qual)) + val end = nextSelect.fold(expire) { x => + prevNonCommentBefore(tokenBefore(x.nameFt)).left + } val exclude = insideBracesBlock(ft, end, parensToo = true) .excludeCloseDelim val bracesToParens = ftAfterRight.right.is[T.OpenDelim] &&