Skip to content

Commit

Permalink
RedundantBraces: don't rewrite {} => () with Defn
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 1, 2020
1 parent 472f54b commit 2c31086
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ object RedundantBraces extends Rewrite {
case _ => false
}

def canRewriteWithParens(b: Term.Block): Boolean = {
def canRewriteWithParens(b: Term.Block): Boolean =
getBlockSingleStat(b).exists {
case f: Term.Function => RedundantBraces.canRewriteWithParens(f)
case f: Term.Function => canRewriteWithParens(f)
case _: Term.Assign => false // disallowed in 2.13
case _: Defn => false
case _ => true
}
}

/* guard for statements requiring a wrapper block
* "foo { x => y; z }" can't become "foo(x => y; z)" */
@tailrec
def canRewriteWithParens(f: Term.Function, nested: Boolean = false): Boolean =
!needParensAroundParams(f) && (getTermSingleStat(f.body) match {
case Some(t: Term.Function) => canRewriteWithParens(t, true)
case Some(_: Defn) => false
case x => nested || x.isDefined
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ object a {
}
}
>>>
test does not parse
object a {
childContext.onDone(_ => val _ = self.withChildren(_.remove(childContext)))
childContext.onDone { _ => val _ = self.withChildren(_.remove(childContext)) }
}
<<< #1756 def within lambda
object a {
Expand All @@ -203,9 +202,8 @@ object a {
}
}
>>>
test does not parse
object a {
childContext.onDone(_ => def a = self.withChildren(_.remove(childContext)))
childContext.onDone { _ => def a = self.withChildren(_.remove(childContext)) }
}
<<< #1756 type within lambda
object a {
Expand All @@ -214,34 +212,30 @@ object a {
}
}
>>>
test does not parse
object a {
childContext.onDone(_ => type a = Int)
childContext.onDone { _ => type a = Int }
}
<<< #1756 val without lambda
object a {
childContext.onDone { val _ = self.withChildren(_.remove(childContext)) }
}
>>>
test does not parse
object a {
childContext.onDone(val _ = self.withChildren(_.remove(childContext)))
childContext.onDone { val _ = self.withChildren(_.remove(childContext)) }
}
<<< #1756 def without lambda
object a {
childContext.onDone { def a = self.withChildren(_.remove(childContext)) }
}
>>>
test does not parse
object a {
childContext.onDone(def a = self.withChildren(_.remove(childContext)))
childContext.onDone { def a = self.withChildren(_.remove(childContext)) }
}
<<< #1756 type without lambda
object a {
childContext.onDone { type a = Int }
}
>>>
test does not parse
object a {
childContext.onDone(type a = Int)
childContext.onDone { type a = Int }
}

0 comments on commit 2c31086

Please sign in to comment.