diff options
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 77 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/ShowPickled.scala | 8 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/Stats.scala | 2 |
3 files changed, 55 insertions, 32 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index b82bd47f6..335d0d66a 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -735,36 +735,59 @@ object desugar { } } - /** Traverse pattern and collect all variable names with their types in buffer. - * Works for expanded as well as unexpanded patterns - */ - private object getVars extends UntypedTreeAccumulator[ListBuffer[VarInfo]] { - override def apply(buf: ListBuffer[VarInfo], tree: Tree): ListBuffer[VarInfo] = { - def seenName(name: Name) = buf exists (_._1.name == name) - def add(named: NameTree, t: Tree): ListBuffer[VarInfo] = - if (seenName(named.name)) buf else buf += ((named, t)) - tree match { - case Bind(nme.WILDCARD, _) => - foldOver(buf, tree) - case tree @ Bind(_, Typed(tree1, tpt)) if !mayBeTypePat(tpt) => - apply(add(tree, tpt), tree1) - case tree @ Bind(_, tree1) => - apply(add(tree, TypeTree()), tree1) - case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD => - add(id, t) - case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD => - add(id, TypeTree()) - case _ => - foldOver(buf, tree) - } - } - } - /** Returns list of all pattern variables, possibly with their types, * without duplicates */ - private def getVariables(tree: Tree): List[VarInfo] = - getVars(new ListBuffer[VarInfo], tree).toList + private def getVariables(tree: Tree)(implicit ctx: Context): List[VarInfo] = { + val buf = new ListBuffer[VarInfo] + def seenName(name: Name) = buf exists (_._1.name == name) + def add(named: NameTree, t: Tree): Unit = + if (!seenName(named.name)) buf += ((named, t)) + def collect(tree: Tree): Unit = tree match { + case Bind(nme.WILDCARD, _) => + collect(tree) + case tree @ Bind(_, Typed(tree1, tpt)) if !mayBeTypePat(tpt) => + add(tree, tpt) + collect(tree1) + case tree @ Bind(_, tree1) => + add(tree, TypeTree()) + collect(tree1) + case Typed(id: Ident, t) if isVarPattern(id) && id.name != nme.WILDCARD => + add(id, t) + case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD => + add(id, TypeTree()) + case Apply(_, args) => + args foreach collect + case Pair(left, right) => + collect(left) + collect(right) + case Typed(expr, _) => + collect(expr) + case NamedArg(_, arg) => + collect(arg) + case SeqLiteral(elems) => + elems foreach collect + case Alternative(trees) => + for (tree <- trees; (vble, _) <- getVariables(tree)) + ctx.error("illegal variable in pattern alternative", vble.pos) + case Annotated(annot, arg) => + collect(arg) + case InterpolatedString(_, _, elems) => + elems foreach collect + case InfixOp(left, _, right) => + collect(left) + collect(right) + case PrefixOp(_, od) => + collect(od) + case Parens(tree) => + collect(tree) + case Tuple(trees) => + trees foreach collect + case _ => + } + collect(tree) + buf.toList + } private class IrrefutableGenFrom(pat: Tree, expr: Tree) extends GenFrom(pat, expr) } diff --git a/src/dotty/tools/dotc/util/ShowPickled.scala b/src/dotty/tools/dotc/util/ShowPickled.scala index ab2801127..71c48042c 100644 --- a/src/dotty/tools/dotc/util/ShowPickled.scala +++ b/src/dotty/tools/dotc/util/ShowPickled.scala @@ -112,7 +112,7 @@ object ShowPickled { result.toInt } - def printFile(buf: PickleBuffer, out: PrintStream = System.out) { + def printFile(buf: PickleBuffer, out: PrintStream = System.out): Unit = { out.println("Version " + buf.readNat() + "." + buf.readNat()) val index = buf.createIndex val entryList = makeEntryList(buf, index) @@ -120,7 +120,7 @@ object ShowPickled { def p(s: String) = out print s - def printNameRef() { + def printNameRef(): Unit = { val idx = buf.readNat() val name = entryList nameAt idx val toPrint = " %s(%s)".format(idx, name) @@ -138,7 +138,7 @@ object ShowPickled { def printConstAnnotArgRef() = printNat() def printAnnotArgRef() = printNat() - def printSymInfo(end: Int) { + def printSymInfo(end: Int): Unit = { printNameRef() printSymbolRef() val pflags = buf.readLongNat() @@ -176,7 +176,7 @@ object ShowPickled { * interpreted are for the most part going to tell you the wrong thing. * It's not so easy to duplicate the logic applied in the UnPickler. */ - def printEntry(i: Int) { + def printEntry(i: Int): Unit = { buf.readIndex = index(i) p(i + "," + buf.readIndex + ": ") val tag = buf.readByte() diff --git a/src/dotty/tools/dotc/util/Stats.scala b/src/dotty/tools/dotc/util/Stats.scala index 3aa6eb9b9..3d7628477 100644 --- a/src/dotty/tools/dotc/util/Stats.scala +++ b/src/dotty/tools/dotc/util/Stats.scala @@ -30,7 +30,7 @@ object Stats { print("|") } - override final def run() { + override final def run(): Unit = { Thread.sleep(HeartBeatPeriod) printStack(stack) if (continue) run() |