From d355f8fe28218b1e8b984d6d491f02c414e922d5 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 12 Apr 2017 15:39:54 +0200 Subject: Dealias before type erasing ... and likewise for taking a signature. The previous case worked in all cases except when faced with an alias like `type Id[T] = T`. In that case, it would disregard the argument and erase to Object. --- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index f35752644..02f1f549f 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -355,7 +355,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean * - For NoType or NoPrefix, the type itself. * - For any other type, exception. */ - private def apply(tp: Type)(implicit ctx: Context): Type = tp match { + private def apply(tp: Type)(implicit ctx: Context): Type = tp.dealias match { case _: ErasedValueType => tp case tp: TypeRef => @@ -487,7 +487,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean * Need to ensure correspondence with erasure! */ private def sigName(tp: Type)(implicit ctx: Context): TypeName = try { - tp match { + tp.dealias match { case ErasedValueType(_, underlying) => sigName(underlying) case tp: TypeRef => -- cgit v1.2.3 From 02cffa49ede84dbd0dbb93329c9a4117251ca658 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 12 Apr 2017 23:56:57 +0200 Subject: Alternative fix Special case HKApply only. This is simpler and potentially more efficient. --- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 02f1f549f..1eb90b8eb 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -355,7 +355,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean * - For NoType or NoPrefix, the type itself. * - For any other type, exception. */ - private def apply(tp: Type)(implicit ctx: Context): Type = tp.dealias match { + private def apply(tp: Type)(implicit ctx: Context): Type = tp match { case _: ErasedValueType => tp case tp: TypeRef => @@ -377,6 +377,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean defn.FunctionType(0) case AndType(tp1, tp2) => erasedGlb(this(tp1), this(tp2), isJava) + case tp: HKApply => + apply(tp.superType) case OrType(tp1, tp2) => ctx.typeComparer.orType(this(tp1), this(tp2), erased = true) case tp: MethodType => @@ -487,7 +489,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean * Need to ensure correspondence with erasure! */ private def sigName(tp: Type)(implicit ctx: Context): TypeName = try { - tp.dealias match { + tp match { case ErasedValueType(_, underlying) => sigName(underlying) case tp: TypeRef => @@ -508,6 +510,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean normalizeClass(sym.asClass).fullName.asTypeName case defn.ArrayOf(elem) => sigName(this(tp)) + case tp: HKApply => + sigName(tp.superType) case JavaArrayType(elem) => sigName(elem) ++ "[]" case tp: TermRef => -- cgit v1.2.3 From 37120df19265da923703de00911e33937e5a66de Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 13 Apr 2017 11:00:37 +0200 Subject: Add test --- tests/pos/i2234.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/pos/i2234.scala diff --git a/tests/pos/i2234.scala b/tests/pos/i2234.scala new file mode 100644 index 000000000..8173c2091 --- /dev/null +++ b/tests/pos/i2234.scala @@ -0,0 +1,13 @@ +object Test { + type Dummy[A] = A + + def a(d: Dummy[String]) = () + def a(d: Dummy[Int]) = () + + implicit def dummy[A]: Dummy[A] = null.asInstanceOf[A] + def m(x: List[String])(implicit d: Dummy[String]) = "string" + def m(x: List[Int])(implicit d: Dummy[Int]) = "int" + + m(List(1, 2, 3)) + m(List("a")) +} -- cgit v1.2.3