Skip to content

Commit 629a4b5

Browse files
committed
also try to register path-dependent types in the bounds
1 parent 62546ae commit 629a4b5

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
@@ -2001,6 +2001,24 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20012001
private def narrowGADTBounds(tr: NamedType, bound: Type, approx: ApproxState, isUpper: Boolean): Boolean = {
20022002
val boundImprecise = approx.high || approx.low
20032003
ctx.mode.is(Mode.GadtConstraintInference) && !frozenGadt && !frozenConstraint && !boundImprecise && {
2004+
def tryRegisterBound: Boolean = bound.match {
2005+
case tr @ TypeRef(path: PathType, _) =>
2006+
val sym = tr.symbol
2007+
2008+
def register =
2009+
ctx.gadt.contains(path, sym) || ctx.gadt.contains(sym) || {
2010+
ctx.gadt.isConstrainablePDT(path, tr.symbol) && {
2011+
gadts.println(i"!!! registering path on the fly path=$path sym=$sym")
2012+
ctx.gadt.addToConstraint(path) && ctx.gadt.contains(path, sym)
2013+
}
2014+
}
2015+
2016+
val result = register
2017+
2018+
true
2019+
case _ => true
2020+
}
2021+
20042022
def narrowTypeParams = ctx.gadt.contains(tr.symbol) && {
20052023
val tparam = tr.symbol
20062024
gadts.println(i"narrow gadt bound of tparam $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound ${bound.toString} ${bound.isRef(tparam)}")
@@ -2042,7 +2060,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20422060

20432061
case _ => false
20442062

2045-
narrowTypeParams || narrowPathDepType
2063+
tryRegisterBound && narrowTypeParams || narrowPathDepType
20462064
}
20472065
}
20482066

0 commit comments

Comments
 (0)