Skip to content

Commit a1d0e49

Browse files
committed
also try to register path-dependent types in the bounds
1 parent 8371bad commit a1d0e49

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
@@ -2084,6 +2084,24 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20842084
private def narrowGADTBounds(tr: NamedType, bound: Type, approx: ApproxState, isUpper: Boolean): Boolean = {
20852085
val boundImprecise = approx.high || approx.low
20862086
ctx.mode.is(Mode.GadtConstraintInference) && !frozenGadt && !frozenConstraint && !boundImprecise && {
2087+
def tryRegisterBound: Boolean = bound.match {
2088+
case tr @ TypeRef(path: PathType, _) =>
2089+
val sym = tr.symbol
2090+
2091+
def register =
2092+
ctx.gadt.contains(path, sym) || ctx.gadt.contains(sym) || {
2093+
ctx.gadt.isConstrainablePDT(path, tr.symbol) && {
2094+
gadts.println(i"!!! registering path on the fly path=$path sym=$sym")
2095+
ctx.gadt.addToConstraint(path) && ctx.gadt.contains(path, sym)
2096+
}
2097+
}
2098+
2099+
val result = register
2100+
2101+
true
2102+
case _ => true
2103+
}
2104+
20872105
def narrowTypeParams = ctx.gadt.contains(tr.symbol) && {
20882106
val tparam = tr.symbol
20892107
gadts.println(i"narrow gadt bound of tparam $tparam: ${tparam.info} from ${if (isUpper) "above" else "below"} to $bound ${bound.toString} ${bound.isRef(tparam)}")
@@ -2125,7 +2143,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21252143

21262144
case _ => false
21272145

2128-
narrowTypeParams || narrowPathDepType
2146+
tryRegisterBound && narrowTypeParams || narrowPathDepType
21292147
}
21302148
}
21312149

0 commit comments

Comments
 (0)