Skip to content

Commit c3c6533

Browse files
oderskysmarter
authored andcommitted
Generalize couldInstantiate
1 parent 5d1e468 commit c3c6533

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ object Inferencing {
8181
if (depVars.nonEmpty) instantiateSelected(tp, depVars.toList)
8282
}
8383

84-
/** If `tp` is type variable with a lower bound in the current constraint,
85-
* instantiate it from below.
84+
/** If `tp` is top-level type variable with a lower bound in the current constraint,
85+
* instantiate it from below. We also look for TypeVars whereever their instantiation
86+
* could uncover new type members.
8687
*/
8788
def couldInstantiateTypeVar(tp: Type)(using Context): Boolean = tp.dealias match
8889
case tvar: TypeVar
@@ -91,6 +92,14 @@ object Inferencing {
9192
&& tvar.hasLowerBound =>
9293
tvar.instantiate(fromBelow = true)
9394
true
95+
case AppliedType(tycon, _) =>
96+
couldInstantiateTypeVar(tycon)
97+
case RefinedType(parent, _, _) =>
98+
couldInstantiateTypeVar(parent)
99+
case tp: AndOrType =>
100+
couldInstantiateTypeVar(tp.tp1) || couldInstantiateTypeVar(tp.tp2)
101+
case AnnotatedType(tp, _) =>
102+
couldInstantiateTypeVar(tp)
94103
case _ =>
95104
false
96105

0 commit comments

Comments
 (0)