Skip to content

Commit e85a2c2

Browse files
committed
Do not constrain types under either approx
1 parent 02a47c7 commit e85a2c2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
12541254
* Test that the resulting bounds are still satisfiable.
12551255
*/
12561256
private def narrowGADTBounds(tr: NamedType, bound: Type, approx: ApproxState, isUpper: Boolean): Boolean = {
1257-
val boundImprecise = if (isUpper) approx.high else approx.low
1257+
val boundImprecise = approx.high || approx.low
12581258
ctx.mode.is(Mode.GADTflexible) && !frozenConstraint && !boundImprecise && {
12591259
val tparam = tr.symbol
12601260
gadts.println(i"narrow gadt bound of $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound ${bound.toString} ${bound.isRef(tparam)}")

tests/neg/gadt-no-approx.scala

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object `gadt-no-approx` {
2+
def fo[U](u: U): U =
3+
(0 : Int) match {
4+
case _: u.type =>
5+
val i: Int = (??? : U) // error
6+
// potentially could compile
7+
// val i2: Int = u
8+
u
9+
}
10+
}

0 commit comments

Comments
 (0)