summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-06-23 06:13:31 +0000
committerPaul Phillips <paulp@improving.org>2011-06-23 06:13:31 +0000
commit8ba9b511c2b11d0514013bb1e18cbc8a7b9e5f5c (patch)
tree0aaa38ebc8e9d7a7c6066db60b0dd9f1e13f390d /src
parent21115422de226f874c73bbfed1a31904432c6e8d (diff)
downloadscala-8ba9b511c2b11d0514013bb1e18cbc8a7b9e5f5c.tar.gz
scala-8ba9b511c2b11d0514013bb1e18cbc8a7b9e5f5c.tar.bz2
scala-8ba9b511c2b11d0514013bb1e18cbc8a7b9e5f5c.zip
Notice when erasure is trying to cast something...
Notice when erasure is trying to cast something to Unit, and don't do it. I'm not sure at what prior point such things should have been caught, but for now we can have a sanity check. Closes #4731, review by odersky.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index c86a7b5867..5f1d5808b4 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -627,8 +627,14 @@ abstract class Erasure extends AddInterfaces
/** Generate a synthetic cast operation from tree.tpe to pt.
* @pre pt eq pt.normalize
*/
- private def cast(tree: Tree, pt: Type): Tree =
- tree AS_ATTR pt
+ private def cast(tree: Tree, pt: Type): Tree = {
+ if (pt.typeSymbol == UnitClass) {
+ // See SI-4731 for one example of how this occurs.
+ log("Attempted to cast to Unit: " + tree)
+ tree.duplicate setType pt
+ }
+ else tree AS_ATTR pt
+ }
private def isUnboxedValueMember(sym: Symbol) =
sym != NoSymbol && isValueClass(sym.owner)
@@ -647,7 +653,7 @@ abstract class Erasure extends AddInterfaces
else if (isValueClass(tree.tpe.typeSymbol) && !isValueClass(pt.typeSymbol))
adaptToType(box(tree), pt)
else if (tree.tpe.isInstanceOf[MethodType] && tree.tpe.params.isEmpty) {
- if (!tree.symbol.isStable) assert(false, "adapt "+tree+":"+tree.tpe+" to "+pt)
+ assert(tree.symbol.isStable, "adapt "+tree+":"+tree.tpe+" to "+pt)
adaptToType(Apply(tree, List()) setPos tree.pos setType tree.tpe.resultType, pt)
} else if (pt <:< tree.tpe)
cast(tree, pt)