diff options
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ElimWildcardIdents.scala | 49 |
2 files changed, 50 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index cb758c002..e8df49008 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -67,7 +67,7 @@ class Compiler { List(new LambdaLift, new Flatten, new RestoreScopes), - List(/*new PrivateToStatic,*/ new CollectEntryPoints, new LabelDefs), + List(/*new PrivateToStatic,*/ new CollectEntryPoints, new LabelDefs, new ElimWildcardIdents), List(new GenBCode) ) diff --git a/src/dotty/tools/dotc/transform/ElimWildcardIdents.scala b/src/dotty/tools/dotc/transform/ElimWildcardIdents.scala new file mode 100644 index 000000000..5ef0dfe84 --- /dev/null +++ b/src/dotty/tools/dotc/transform/ElimWildcardIdents.scala @@ -0,0 +1,49 @@ +package dotty.tools.dotc.transform + +import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, TreeTransformer, MiniPhaseTransform} +import dotty.tools.dotc.ast.{untpd, tpd} +import dotty.tools.dotc.core.Contexts.Context +import scala.collection.mutable.ListBuffer +import dotty.tools.dotc.core.{Scopes, Flags} +import dotty.tools.dotc.core.Symbols.NoSymbol +import scala.annotation.tailrec +import dotty.tools.dotc.core._ +import Symbols._ +import scala.Some +import dotty.tools.dotc.transform.TreeTransforms.{NXTransformations, TransformerInfo, TreeTransform, TreeTransformer} +import dotty.tools.dotc.core.Contexts.Context +import scala.collection.mutable +import dotty.tools.dotc.core.Names.Name +import NameOps._ +import Types._ +import scala.collection.SortedSet +import Decorators._ +import StdNames._ +import dotty.tools.dotc.util.Positions.Position +import dotty.tools.dotc.config.JavaPlatform + +/** + * Replace Ident("_") in tree with default values of corresponding type: + * numerics: `0` + * booleans: `false` + * classes: `null` + */ +class ElimWildcardIdents extends MiniPhaseTransform { + import tpd._ + def phaseName: String = "elimWildcardIdents" + + + override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = { + def stripBlocks(arg: Tree): Tree = arg match { + case b: Block if b.stats.isEmpty => stripBlocks(b.expr) + case _ => arg + } + val b = stripBlocks(tree.rhs) + b match { + case x: Ident if (x.name == nme.WILDCARD && x.symbol.isClass) => + tpd.DefDef(tree.symbol.asTerm, tpd.initValue(x.tpe)) + case _ => tree + } + } + +} |