From 8377c0da86f7e9959e40e4b863a4831df9947e67 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Mon, 3 Apr 2017 21:20:24 +0200 Subject: [PATCH 1/3] Fixes @unchecked warnings --- compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala | 2 +- compiler/src/dotty/tools/dotc/transform/PostTyper.scala | 6 +++--- compiler/src/dotty/tools/dotc/transform/TreeChecker.scala | 2 +- compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala index 6c7982d780ab..e9449a312954 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala @@ -159,7 +159,7 @@ class TreeBuffer extends TastyBuffer(50000) { val tree = it.next treeAddrs.get(tree) match { case addr: Addr => treeAddrs.put(tree, adjusted(addr)) - case addrs: List[Addr] => treeAddrs.put(tree, addrs.map(adjusted)) + case addrs: List[Addr @unchecked] => treeAddrs.put(tree, addrs.map(adjusted)) } } } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 8dff58dea8c6..1a6ebb65dba0 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -264,9 +264,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran ctx.error(s"${ident.name} is not a member of ${expr.show}", ident.pos) } selectors.foreach { - case ident: Ident => checkIdent(ident) - case Thicket((ident: Ident) :: _) => checkIdent(ident) - case _ => + case ident @ Ident(_) => checkIdent(ident) + case Thicket((ident @ Ident(_)) :: _) => checkIdent(ident) + case _ => } super.transform(tree) case tree => diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 51e2469b2314..e478d6127687 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -145,7 +145,7 @@ class TreeChecker extends Phase with SymTransformer { override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = () def withDefinedSym[T](tree: untpd.Tree)(op: => T)(implicit ctx: Context): T = tree match { - case tree: DefTree => + case tree: DefTree @unchecked => val sym = tree.symbol assert(isValidJVMName(sym.name), s"${sym.fullName} name is invalid on jvm") everDefinedSyms.get(sym) match { diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index f7dd725c8672..ed274a3dc200 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -539,7 +539,7 @@ object ProtoTypes { /** Dummy tree to be used as an argument of a FunProto or ViewProto type */ object dummyTreeOfType { def apply(tp: Type): Tree = untpd.Literal(Constant(null)) withTypeUnchecked tp - def unapply(tree: Tree): Option[Type] = tree match { + def unapply(tree: Tree @unchecked): Option[Type] = tree match { case Literal(Constant(null)) => Some(tree.typeOpt) case _ => None } From 4aba4f798d2027a94b07631fd0589abe60eb644e Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Mon, 3 Apr 2017 21:24:28 +0200 Subject: [PATCH 2/3] Use `mapConserve` in `UntypedTreeMap` --- compiler/src/dotty/tools/dotc/ast/untpd.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 8ca91590f5dc..682d1680dfab 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -477,7 +477,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { case SymbolLit(str) => cpy.SymbolLit(tree)(str) case InterpolatedString(id, segments) => - cpy.InterpolatedString(tree)(id, segments.map(transform(_))) + cpy.InterpolatedString(tree)(id, segments.mapConserve(transform)) case Function(args, body) => cpy.Function(tree)(transform(args), transform(body)) case InfixOp(left, op, right) => From fee6953c75eb93956e4e33ff8351aa2ec992854c Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 4 Apr 2017 11:27:06 +0200 Subject: [PATCH 3/3] Addresses review comments --- .../src/dotty/tools/dotc/core/tasty/TreeBuffer.scala | 1 - .../src/dotty/tools/dotc/transform/PostTyper.scala | 10 +++++----- .../src/dotty/tools/dotc/transform/TreeChecker.scala | 6 +++--- compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala index e9449a312954..86e5be2e26f7 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeBuffer.scala @@ -159,7 +159,6 @@ class TreeBuffer extends TastyBuffer(50000) { val tree = it.next treeAddrs.get(tree) match { case addr: Addr => treeAddrs.put(tree, adjusted(addr)) - case addrs: List[Addr @unchecked] => treeAddrs.put(tree, addrs.map(adjusted)) } } } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 1a6ebb65dba0..9821757e8991 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -2,7 +2,7 @@ package dotty.tools.dotc package transform import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, TreeTransformer} -import dotty.tools.dotc.ast.{Trees, tpd} +import dotty.tools.dotc.ast.{Trees, tpd, untpd} import scala.collection.{ mutable, immutable } import ValueClasses._ import scala.annotation.tailrec @@ -258,15 +258,15 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran ) case Import(expr, selectors) => val exprTpe = expr.tpe - def checkIdent(ident: Ident): Unit = { + def checkIdent(ident: untpd.Ident): Unit = { val name = ident.name.asTermName.encode if (name != nme.WILDCARD && !exprTpe.member(name).exists && !exprTpe.member(name.toTypeName).exists) ctx.error(s"${ident.name} is not a member of ${expr.show}", ident.pos) } selectors.foreach { - case ident @ Ident(_) => checkIdent(ident) - case Thicket((ident @ Ident(_)) :: _) => checkIdent(ident) - case _ => + case ident: untpd.Ident => checkIdent(ident) + case Thicket((ident: untpd.Ident) :: _) => checkIdent(ident) + case _ => } super.transform(tree) case tree => diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index e478d6127687..dd4d95257aad 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -139,13 +139,13 @@ class TreeChecker extends Phase with SymTransformer { class Checker(phasesToCheck: Seq[Phase]) extends ReTyper with Checking { val nowDefinedSyms = new mutable.HashSet[Symbol] - val everDefinedSyms = new mutable.HashMap[Symbol, Tree] + val everDefinedSyms = new mutable.HashMap[Symbol, untpd.Tree] // don't check value classes after typer, as the constraint about constructors doesn't hold after transform override def checkDerivedValueClass(clazz: Symbol, stats: List[Tree])(implicit ctx: Context) = () def withDefinedSym[T](tree: untpd.Tree)(op: => T)(implicit ctx: Context): T = tree match { - case tree: DefTree @unchecked => + case tree: untpd.DefTree => val sym = tree.symbol assert(isValidJVMName(sym.name), s"${sym.fullName} name is invalid on jvm") everDefinedSyms.get(sym) match { @@ -160,7 +160,7 @@ class TreeChecker extends Phase with SymTransformer { if (ctx.settings.YcheckMods.value) { tree match { - case t: MemberDef => + case t: untpd.MemberDef => if (t.name ne sym.name) ctx.warning(s"symbol ${sym.fullName} name doesn't correspond to AST: ${t}") // todo: compare trees inside annotations case _ => diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index ed274a3dc200..f96b8ae1dd2c 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -539,7 +539,7 @@ object ProtoTypes { /** Dummy tree to be used as an argument of a FunProto or ViewProto type */ object dummyTreeOfType { def apply(tp: Type): Tree = untpd.Literal(Constant(null)) withTypeUnchecked tp - def unapply(tree: Tree @unchecked): Option[Type] = tree match { + def unapply(tree: untpd.Tree): Option[Type] = tree match { case Literal(Constant(null)) => Some(tree.typeOpt) case _ => None }