Skip to content

Commit 56dcc55

Browse files
committed
also try to register path-dependent types in the bounds
1 parent d49d15e commit 56dcc55

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,24 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20022002
private def narrowGADTBounds(tr: NamedType, bound: Type, approx: ApproxState, isUpper: Boolean): Boolean = {
20032003
val boundImprecise = approx.high || approx.low
20042004
ctx.mode.is(Mode.GadtConstraintInference) && !frozenGadt && !frozenConstraint && !boundImprecise && {
2005+
def tryRegisterBound: Boolean = bound.match {
2006+
case tr @ TypeRef(path: PathType, _) =>
2007+
val sym = tr.symbol
2008+
2009+
def register =
2010+
ctx.gadt.contains(path, sym) || ctx.gadt.contains(sym) || {
2011+
ctx.gadt.isConstrainablePDT(path, tr.symbol) && {
2012+
gadts.println(i"!!! registering path on the fly path=$path sym=$sym")
2013+
ctx.gadt.addToConstraint(path) && ctx.gadt.contains(path, sym)
2014+
}
2015+
}
2016+
2017+
val result = register
2018+
2019+
true
2020+
case _ => true
2021+
}
2022+
20052023
def narrowTypeParams = ctx.gadt.contains(tr.symbol) && {
20062024
val tparam = tr.symbol
20072025
gadts.println(i"narrow gadt bound of tparam $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound ${bound.toString} ${bound.isRef(tparam)}")
@@ -2043,7 +2061,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20432061

20442062
case _ => false
20452063

2046-
narrowTypeParams || narrowPathDepType
2064+
tryRegisterBound && narrowTypeParams || narrowPathDepType
20472065
}
20482066
}
20492067

0 commit comments

Comments
 (0)