Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedundantBraces: keep some around PartialFunction #4374

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,17 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
owner match {
case t: Term.FunctionTerm if t.tokens.last.is[Token.RightBrace] =>
if (!okToRemoveFunctionInApplyOrInit(t)) null else removeToken
case t: Term.PartialFunction if t.parent.exists { p =>
SingleArgInBraces.orBlock(p).exists(_._2 eq t) &&
t.pos.start != p.pos.start
} => removeToken
case t: Term.PartialFunction => t.parent match {
case Some(SingleArgInBraces.OrBlock(lft, `t`, _))
if lft.left ne ft.right =>
val ok = ftoks.findTokenWith(lft, ftoks.prev) { xft =>
if (!xft.left.is[Token.LeftBrace]) Some(false)
else if (session.isRemovedOnLeft(xft, ok = true)) None
else Some(true)
}.contains(true)
if (ok) removeToken else null
case _ => null
}
case t: Term.Block => t.parent match {
case Some(f: Term.FunctionTerm)
if okToReplaceFunctionInSingleArgApply(f) => removeToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,23 @@ object a:
end if
else checkJSNativeLoadSpecOf(treePos, sym)
end if
<<< #4133 partial function within if-else
val toIterator: Any => Iterator[_] = if (lenient) {
{
case i: scala.collection.Iterable[_] => i.iterator
case l: java.util.List[_] => l.iterator().asScala
case a: Array[_] => a.iterator
case o => unsupportedCollectionType(o.getClass)
}
} else {
unsupportedCollectionType(tag.runtimeClass)
}
>>>
val toIterator: Any => Iterator[_] = if (lenient) {
case i: scala.collection.Iterable[_] => i.iterator
case l: java.util.List[_] => l.iterator().asScala
case a: Array[_] => a.iterator
case o => unsupportedCollectionType(o.getClass)
}
else
unsupportedCollectionType(tag.runtimeClass)
Loading