aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-05-06 10:22:19 +0200
committerMartin Odersky <odersky@gmail.com>2015-05-06 10:22:25 +0200
commitd26604fd50bd2c444c9dd108781d36864380b5f2 (patch)
tree06f3fa47a840dbd06dacea0d1294fc29310da2da
parent7129cbe60c062be49aef8c27da461a11416e189c (diff)
downloaddotty-d26604fd50bd2c444c9dd108781d36864380b5f2.tar.gz
dotty-d26604fd50bd2c444c9dd108781d36864380b5f2.tar.bz2
dotty-d26604fd50bd2c444c9dd108781d36864380b5f2.zip
Fix #540 - unbounded array test for wildcard array arguments
Arrays with wildcard arguments such as Array[_ <: Foo] where Foo is a universal trait are now diagnosed as unbounded generic arrays and are erased to Object.
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala4
-rw-r--r--tests/pos/i540.scala6
2 files changed, 9 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index 71146bd4e..f499e2ece 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -182,13 +182,14 @@ object TypeErasure {
case tp: PolyParam =>
!tp.derivesFrom(defn.ObjectClass) &&
!tp.binder.resultType.isInstanceOf[JavaMethodType]
+ case tp: TypeAlias => isUnboundedGeneric(tp.alias)
+ case tp: TypeBounds => !tp.hi.derivesFrom(defn.ObjectClass)
case tp: TypeProxy => isUnboundedGeneric(tp.underlying)
case tp: AndType => isUnboundedGeneric(tp.tp1) || isUnboundedGeneric(tp.tp2)
case tp: OrType => isUnboundedGeneric(tp.tp1) && isUnboundedGeneric(tp.tp2)
case _ => false
}
-
/** The erased least upper bound is computed as follows
* - if both argument are arrays, an array of the lub of the element types
* - if one argument is an array, Object
@@ -365,6 +366,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
val defn.ArrayType(elemtp) = tp
def arrayErasure(tpToErase: Type) =
erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(tpToErase)
+ println(s"erase array, elemtp = $elemtp")
if (elemtp derivesFrom defn.NullClass) JavaArrayType(defn.ObjectType)
else if (isUnboundedGeneric(elemtp)) defn.ObjectType
else JavaArrayType(arrayErasure(elemtp))
diff --git a/tests/pos/i540.scala b/tests/pos/i540.scala
new file mode 100644
index 000000000..b7540ab2c
--- /dev/null
+++ b/tests/pos/i540.scala
@@ -0,0 +1,6 @@
+trait Foo extends Any
+
+object Univ {
+ def univ[T <: Foo](x: Array[T]) = {}
+ def univ2(x: Array[_ <: Foo]) = {}
+}