aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-25 09:45:50 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-25 09:45:50 +0200
commit15fb8e160210e20ec9bec949f23e08ef045b1545 (patch)
tree874ebc9457a0ea2ea4b1c912c5698d998b678722 /src
parent11f06fe8435c118a8476b2c197c1973ea4c647aa (diff)
downloaddotty-15fb8e160210e20ec9bec949f23e08ef045b1545.tar.gz
dotty-15fb8e160210e20ec9bec949f23e08ef045b1545.tar.bz2
dotty-15fb8e160210e20ec9bec949f23e08ef045b1545.zip
Fix #1284: Make classTag depend directly on erasure
In the end, a classTag reflects the erased version of a type. The only condition for its generation should be that the erasure is stable under possible instantiations.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala18
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala16
2 files changed, 25 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index a1dab16cb..1a7342a12 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -277,6 +277,22 @@ object TypeErasure {
else tp1
}
}
+
+ /** Does the (possibly generic) type `tp` have the same erasure in all its
+ * possible instantiations?
+ */
+ def hasStableErasure(tp: Type)(implicit ctx: Context): Boolean = tp match {
+ case tp: TypeRef =>
+ tp.info match {
+ case TypeAlias(alias) => hasStableErasure(alias)
+ case _: ClassInfo => true
+ case _ => false
+ }
+ case tp: PolyParam => false
+ case tp: TypeProxy => hasStableErasure(tp.superType)
+ case tp: AndOrType => hasStableErasure(tp.tp1) && hasStableErasure(tp.tp2)
+ case _ => false
+ }
}
import TypeErasure._
@@ -493,4 +509,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
println(s"no sig for $tp")
throw ex
}
+
+
}
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index feed398aa..1eba64e2e 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -10,6 +10,7 @@ import printing.Showable
import Contexts._
import Types._
import Flags._
+import TypeErasure.{erasure, hasStableErasure}
import Mode.ImplicitsEnabled
import Denotations._
import NameOps._
@@ -479,15 +480,12 @@ trait Implicits { self: Typer =>
formal.argTypes match {
case arg :: Nil =>
val tp = fullyDefinedType(arg, "ClassTag argument", pos)
- tp.underlyingClassRef(refinementOK = false) match {
- case tref: TypeRef =>
- return ref(defn.ClassTagModule)
- .select(nme.apply)
- .appliedToType(tp)
- .appliedTo(clsOf(tref))
- .withPos(pos)
- case _ =>
- }
+ if (hasStableErasure(tp))
+ return ref(defn.ClassTagModule)
+ .select(nme.apply)
+ .appliedToType(tp)
+ .appliedTo(clsOf(erasure(tp)))
+ .withPos(pos)
case _ =>
}
EmptyTree