summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2010-02-25 15:53:13 +0000
committerIulian Dragos <jaguarul@gmail.com>2010-02-25 15:53:13 +0000
commitf479aff2745e0b382ec9eea9d0b6b473e73c23e0 (patch)
treef344af4124f628d6fa1559c8d76c2b9639e52783 /src
parentc6facf49bb442213fc9919428dad7716662e950c (diff)
downloadscala-f479aff2745e0b382ec9eea9d0b6b473e73c23e0.tar.gz
scala-f479aff2745e0b382ec9eea9d0b6b473e73c23e0.tar.bz2
scala-f479aff2745e0b382ec9eea9d0b6b473e73c23e0.zip
Made the squeezer worthy of its name: a block w...
Made the squeezer worthy of its name: a block with an empty list of stats and another block as the result expression is rewritten to the inner block (recursively). This makes the output from the pattern matcher nicer, eliminating loads of empty nested blocks. Review by extempore.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
index 23944c91d9..74de20de4a 100644
--- a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
+++ b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala
@@ -30,9 +30,16 @@ trait MatrixAdditions extends ast.TreeDSL
def squeezedBlockPVs(pvs: List[PatternVar], exp: Tree): Tree =
squeezedBlock(pvs map (_.valDef), exp)
+ def mkBlock(stats: List[Tree], expr: Tree): Tree =
+ if (stats.isEmpty) expr match {
+ case Block(stats1, expr1) => mkBlock(stats1, expr1)
+ case _ => Block(stats, expr)
+ } else
+ Block(stats, expr)
+
def squeezedBlock(vds: List[Tree], exp: Tree): Tree =
- if (settings_squeeze) Block(Nil, squeezedBlock1(vds, exp))
- else Block(vds, exp)
+ if (settings_squeeze) mkBlock(Nil, squeezedBlock1(vds, exp))
+ else mkBlock(vds, exp)
private def squeezedBlock1(vds: List[Tree], exp: Tree): Tree = {
class RefTraverser(sym: Symbol) extends Traverser {