Skip to content

Commit 5b03dca

Browse files
committed
Refactor type instantiation logic when typing function values to handle union types
1 parent f3aea49 commit 5b03dca

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,13 +1929,21 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19291929
NoType
19301930
}
19311931

1932-
if pt.existsPart(_.isInstanceOf[TypeVar], StopAt.Static)
1933-
&& untpd.isFunctionWithUnknownParamType(tree)
1934-
&& !calleeType.exists then
1932+
def instantiateInUnion(tp: Type): Unit = tp match
1933+
case tp: OrType =>
1934+
instantiateInUnion(tp.tp1)
1935+
instantiateInUnion(tp.tp2)
1936+
case tp: FlexibleType =>
1937+
instantiateInUnion(tp.hi)
1938+
case tp: TypeVar =>
1939+
isFullyDefined(tp, ForceDegree.flipBottom)
1940+
case _ =>
1941+
1942+
if untpd.isFunctionWithUnknownParamType(tree) && !calleeType.exists then
19351943
// try to instantiate `pt` if this is possible. If it does not
19361944
// work the error will be reported later in `inferredParam`,
19371945
// when we try to infer the parameter type.
1938-
isFullyDefined(pt, ForceDegree.flipBottom)
1946+
instantiateInUnion(pt)
19391947

19401948
val (protoFormals, resultTpt) = decomposeProtoFunction(pt, params.length, tree.srcPos)
19411949

0 commit comments

Comments
 (0)