Skip to content

Commit 201c25a

Browse files
committed
Match the single TypeVar case with the previous logic
1 parent df5e0c9 commit 201c25a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19321932
/** Try to instantiate one type variable bounded by function types that appear
19331933
* deeply inside `tp`, including union or intersection types.
19341934
*/
1935-
def tryToInstantiateDeeply(tp: Type): Boolean = tp match
1935+
def tryToInstantiateDeeply(tp: Type): Boolean = tp.dealias match
19361936
case tp: AndOrType =>
19371937
tryToInstantiateDeeply(tp.tp1)
19381938
|| tryToInstantiateDeeply(tp.tp2)
@@ -1946,6 +1946,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19461946
def isConstrainedByFunctionType(tvar: TypeVar): Boolean =
19471947
val origin = tvar.origin
19481948
val bounds = ctx.typerState.constraint.bounds(origin)
1949+
// The search is done by the best-effort, and we don't look into TypeVars recursively.
19491950
def containsFunctionType(tp: Type): Boolean = tp.dealias match
19501951
case tp if defn.isFunctionType(tp) => true
19511952
case SAMType(_, _) => true
@@ -1957,11 +1958,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19571958
containsFunctionType(bounds.lo) || containsFunctionType(bounds.hi)
19581959

19591960
if untpd.isFunctionWithUnknownParamType(tree) && !calleeType.exists then
1960-
// Try to instantiate `pt` when possible, by searching a nested type variable
1961-
// bounded by function types to help infer parameter types.
1961+
// Try to instantiate `pt` when possible.
1962+
// * If `pt` is a type variable, we try to instantiate it directly.
1963+
// * If `pt` is a more complex type, we try to instantiate it deeply by searching
1964+
// a nested type variable bounded by function types to help infer parameter types.
19621965
// If it does not work the error will be reported later in `inferredParam`,
19631966
// when we try to infer the parameter type.
1964-
tryToInstantiateDeeply(pt)
1967+
pt match
1968+
case pt: TypeVar => isFullyDefined(pt, ForceDegree.flipBottom)
1969+
case _ => tryToInstantiateDeeply(pt)
19651970

19661971
val (protoFormals, resultTpt) = decomposeProtoFunction(pt, params.length, tree.srcPos)
19671972

0 commit comments

Comments
 (0)