Skip to content

Commit

Permalink
Merge pull request #2832 from zivver/fix-infix-new-object
Browse files Browse the repository at this point in the history
#2830 Add Term.New check to AvoidInfix
  • Loading branch information
tgodzik committed Oct 29, 2021
2 parents 8048cee + 13512d8 commit 9b2c65a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class AvoidInfix(implicit ctx: RewriteCtx) extends RewriteSession {
} =>
if (RewriteCtx.hasPlaceholder(lhs)) return
true
case _: Term.Eta => true // foo _ compose bar => (foo _).compose(bar)
// foo _ compose bar => (foo _).compose(bar)
// new Foo compose bar => (new Foo).compose(bar)
case _: Term.Eta | _: Term.New => true
case _ => false
}
if (shouldWrapLhs) {
Expand Down
24 changes: 24 additions & 0 deletions scalafmt-tests/src/test/resources/rewrite/AvoidInfix3.stat
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ object a {
object a {
b.c(foo bar _.baz(0))
}
<<< #2830 1
object a {
new Foo run bar
}
>>>
object a {
(new Foo).run(bar)
}
<<< #2830 2
object a {
new Foo run new Bar
}
>>>
object a {
(new Foo).run(new Bar)
}
<<< #2830 3
object a {
new Foo(a, b) run new Bar
}
>>>
object a {
(new Foo(a, b)).run(new Bar)
}
<<< #1047 1
val i: Ordering[I] = Ordering.fromLessThan(_.i isAfter _.i)
>>>
Expand Down

0 comments on commit 9b2c65a

Please sign in to comment.