Skip to content

Commit 01dbaeb

Browse files
committed
Fix #6146: Fix bounds check involving wildcards and f-bounds
Don't map arguments to their upper bounds before doing the bound check. There was a comment justifiying that by talking about non fully-determined arguments, but this check is done in PostTyper when all types should already be fully-determined. Given that this comment was written in 2014 I'm assuming it's no longer relevant.
1 parent ac7e226 commit 01dbaeb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
265265
def checkOverlapsBounds(lo: Type, hi: Type): Unit = {
266266
//println(i"instantiating ${bounds.hi} with $argTypes")
267267
//println(i" = ${instantiate(bounds.hi, argTypes)}")
268-
val hiBound = instantiate(bounds.hi, argTypes.mapConserve(_.bounds.hi))
269-
val loBound = instantiate(bounds.lo, argTypes.mapConserve(_.bounds.lo))
270-
// Note that argTypes can contain a TypeBounds type for arguments that are
271-
// not fully determined. In that case we need to check against the hi bound of the argument.
268+
val hiBound = instantiate(bounds.hi, argTypes)
269+
val loBound = instantiate(bounds.lo, argTypes)
272270
if (!(lo <:< hiBound)) violations += ((arg, "upper", hiBound))
273271
if (!(loBound <:< hi)) violations += ((arg, "lower", bounds.lo))
274272
}

tests/pos/i6146.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait BS[T, S <: BS[T, S]]
2+
trait IS extends BS[Int, IS]
3+
4+
sealed trait BSElem[T, S <: BS[_, S]]
5+
// old error: Type argument S does not conform to upper bound BS[Any, LazyRef(S)]
6+
7+
object BSElem {
8+
implicit val intStreamShape: BSElem[Int, IS] = ???
9+
}
10+
class Ops[A] {
11+
def asJavaSeqStream[S <: BS[_, S]](implicit s: BSElem[A, S]): S = ???
12+
// old error: Type argument S does not conform to upper bound BS[Any, LazyRef(S)]
13+
}

0 commit comments

Comments
 (0)