Skip to content

Commit 9570da9

Browse files
committed
Fix isUnboundedGeneric for &/| types
This also fixes #1747 by allowing the same encoding as `scalac` to cope with overridden methods over unbounded generic arrays.
1 parent 66af44f commit 9570da9

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ object TypeErasure {
211211
case tp: TypeAlias => isUnboundedGeneric(tp.alias)
212212
case tp: TypeBounds => !tp.hi.derivesFrom(defn.ObjectClass)
213213
case tp: TypeProxy => isUnboundedGeneric(tp.underlying)
214-
case tp: AndType => isUnboundedGeneric(tp.tp1) || isUnboundedGeneric(tp.tp2)
215-
case tp: OrType => isUnboundedGeneric(tp.tp1) && isUnboundedGeneric(tp.tp2)
214+
case tp: AndType => isUnboundedGeneric(tp.tp1) && isUnboundedGeneric(tp.tp2)
215+
case tp: OrType => isUnboundedGeneric(tp.tp1) || isUnboundedGeneric(tp.tp2)
216216
case _ => false
217217
}
218218

tests/neg/i1747.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
class Coll[E] extends java.util.Collection[E] { // error: needs to be abstract
2-
def toArray[T](a: Array[T]): Array[T] = ??? // error: cannot override
1+
abstract class Coll[E] extends java.util.Collection[E] {
2+
override def toArray[T](a: Array[T]): Array[T] = ??? // error: has different signature
33
}

tests/pos/i1747.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
abstract class Coll[E] extends java.util.Collection[E] {
2+
override def toArray[T](a: Array[T with Object]): Array[T with Object] = ??? // error: cannot override
3+
}

0 commit comments

Comments
 (0)