Skip to content

Commit 5eae6e5

Browse files
committed
Do not constrain types under either approx
1 parent 7f7471b commit 5eae6e5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
12491249
* Test that the resulting bounds are still satisfiable.
12501250
*/
12511251
private def narrowGADTBounds(tr: NamedType, bound: Type, approx: ApproxState, isUpper: Boolean): Boolean = {
1252-
val boundImprecise = if (isUpper) approx.high else approx.low
1252+
val boundImprecise = approx.high || approx.low
12531253
ctx.mode.is(Mode.GADTflexible) && !frozenConstraint && !boundImprecise && {
12541254
val tparam = tr.symbol
12551255
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

Lines changed: 10 additions & 0 deletions
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)