Skip to content

Commit 160f63f

Browse files
committed
Fix #523: Instantiate lower bound when bounds checking
Lower bounds need to be instantiated just like upper bounds. F-bounded polymorphism (which only applies too upper bounds) is one reason for instantiating arguments, but parameters referring to other parameters is another one. An the latter applies to lower bounds as well.
1 parent ac46a0e commit 160f63f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
352352
//println(i"instantiating ${bounds.hi} with $argTypes")
353353
//println(i" = ${instantiate(bounds.hi, argTypes)}")
354354
val hiBound = instantiate(bounds.hi, argTypes.mapConserve(_.bounds.hi))
355+
val loBound = instantiate(bounds.lo, argTypes.mapConserve(_.bounds.lo))
355356
// Note that argTypes can contain a TypeBounds type for arguments that are
356357
// not fully determined. In that case we need to check against the hi bound of the argument.
357358
if (!(lo <:< hiBound)) violations += ((arg, "upper", hiBound))
358-
if (!(bounds.lo <:< hi)) violations += ((arg, "lower", bounds.lo))
359+
if (!(loBound <:< hi)) violations += ((arg, "lower", bounds.lo))
359360
}
360361
arg.tpe match {
361362
case TypeBounds(lo, hi) => checkOverlapsBounds(lo, hi)

tests/pos/i523.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class X
2+
class A {
3+
def foo[T1, T2 >: T1]: Unit = {}
4+
5+
def test = {
6+
foo[X, X]
7+
}
8+
}

0 commit comments

Comments
 (0)