File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,19 @@ 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.
86+ */
87+ def couldInstantiateTypeVar (tp : Type )(using Context ): Boolean = tp.dealias match
88+ case tvar : TypeVar
89+ if ! tvar.isInstantiated
90+ && ctx.typerState.constraint.contains(tvar)
91+ && tvar.hasLowerBound =>
92+ tvar.instantiate(fromBelow = true )
93+ true
94+ case _ =>
95+ false
96+
8497 /** The accumulator which forces type variables using the policy encoded in `force`
8598 * and returns whether the type is fully defined. The direction in which
8699 * a type variable is instantiated is determined as follows:
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import config.Printers.typr
1212import ast .Trees ._
1313import NameOps ._
1414import ProtoTypes ._
15- import Inferencing .isFullyDefined
15+ import Inferencing .couldInstantiateTypeVar
1616import collection .mutable
1717import reporting ._
1818import Checking .{checkNoPrivateLeaks , checkNoWildcard }
@@ -160,7 +160,7 @@ trait TypeAssigner {
160160 TryDynamicCallType
161161 else if (qualType.isErroneous || name.toTermName == nme.ERROR )
162162 UnspecifiedErrorType
163- else if ! isFullyDefined (qualType, ForceDegree .none) && isFullyDefined(qualType, ForceDegree .failBottom ) then
163+ else if couldInstantiateTypeVar (qualType) then
164164 // try again with more defined qualifier type
165165 selectionType(tree, qual1)
166166 else if (name == nme.CONSTRUCTOR )
You can’t perform that action at this time.
0 commit comments