diff options
author | Martin Odersky <odersky@gmail.com> | 2014-08-30 17:23:22 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-08-30 17:23:22 +0200 |
commit | 5e7c262bf08fafb8ced88688121a05efda81f21b (patch) | |
tree | 9f86e7e997d9ed5ec2cbd713d3658d648e3a2cef | |
parent | 4041c5d590f78323d640c6eec7e370a37a01c416 (diff) | |
download | dotty-5e7c262bf08fafb8ced88688121a05efda81f21b.tar.gz dotty-5e7c262bf08fafb8ced88688121a05efda81f21b.tar.bz2 dotty-5e7c262bf08fafb8ced88688121a05efda81f21b.zip |
Moving an assertion from erasure to TreeChecker.
The move caught an illegal erased type in a SelectFromType node.
-rw-r--r-- | src/dotty/tools/dotc/transform/Erasure.scala | 18 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/TreeChecker.scala | 12 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ReTyper.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 2 |
4 files changed, 19 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index ba6e1dbe0..7100e4528 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -270,6 +270,9 @@ object Erasure { recur(typed(tree.qualifier, AnySelectionProto)) } + override def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context) = + untpd.Ident(tree.name).withPos(tree.pos).withType(erasedType(tree)) + private def runtimeCallWithProtoArgs(name: Name, pt: Type, args: Tree*)(implicit ctx: Context): Tree = { val meth = defn.runtimeMethod(name) val followingParams = meth.info.firstParamTypes.drop(args.length) @@ -420,18 +423,7 @@ object Erasure { assert(ctx.phase == ctx.erasurePhase.next, ctx.phase) if (tree.isEmpty) tree else if (ctx.mode is Mode.Pattern) tree // TODO: replace with assertion once pattern matcher is active - else { - val tree1 = adaptToType(tree, pt) - tree1.tpe match { - case ref: TermRef => - assert( - ref.isInstanceOf[WithNonMemberSym] || - ref.denot.isInstanceOf[SymDenotation], - i"non-sym type $ref of class ${ref.getClass} with denot of class ${ref.denot.getClass} of $tree1") - case _ => - } - tree1 - } - } + else adaptToType(tree, pt) + } } } diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index bd7e351e1..c3e2278ad 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -126,10 +126,22 @@ class TreeChecker { def assertErased(tp: Type, tree: Tree = EmptyTree)(implicit ctx: Context): Unit = assert(isErasedType(tp), i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase}") + /** Assert that tree type and its widened underlying type are erased. + * Also assert that term refs have fixed symbols (so we are sure + * they need not be reloaded using member; this would likely fail as signatures + * may change after erasure). + */ def assertErased(tree: Tree)(implicit ctx: Context): Unit = { assertErased(tree.typeOpt, tree) if (!(tree.symbol == defn.Any_isInstanceOf || tree.symbol == defn.Any_asInstanceOf)) assertErased(tree.typeOpt.widen, tree) + if (ctx.mode.isExpr) + tree.tpe match { + case ref: TermRef => + assert(ref.denot.isInstanceOf[SymDenotation], + i"non-sym type $ref of class ${ref.getClass} with denot of class ${ref.denot.getClass} of $tree") + case _ => + } } } diff --git a/src/dotty/tools/dotc/typer/ReTyper.scala b/src/dotty/tools/dotc/typer/ReTyper.scala index 4014aa202..3826531cb 100644 --- a/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/src/dotty/tools/dotc/typer/ReTyper.scala @@ -35,7 +35,7 @@ class ReTyper extends Typer { untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt) } - override def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): SelectFromTypeTree = { + override def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = { assert(tree.hasType) val qual1 = typed(tree.qualifier, AnySelectionProto) untpd.cpy.SelectFromTypeTree(tree)(qual1, tree.name).withType(tree.typeOpt) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f21528da0..f58ccbdbc 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -283,7 +283,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit checkValue(assignType(cpy.Select(tree)(qual1, tree.name), qual1), pt) } - def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): SelectFromTypeTree = track("typedSelectFromTypeTree") { + def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = track("typedSelectFromTypeTree") { val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this)) checkLegalPrefix(qual1.tpe, tree.name, qual1.pos) assignType(cpy.SelectFromTypeTree(tree)(qual1, tree.name), qual1) |