Skip to content

Commit d93ed6c

Browse files
committed
Refactor type instantiation logic when typing function values to handle union types
1 parent 584c069 commit d93ed6c

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
@@ -1921,13 +1921,21 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19211921
NoType
19221922
}
19231923

1924-
if pt.existsPart(_.isInstanceOf[TypeVar], StopAt.Static)
1925-
&& untpd.isFunctionWithUnknownParamType(tree)
1926-
&& !calleeType.exists then
1924+
def instantiateInUnion(tp: Type): Unit = tp match
1925+
case tp: OrType =>
1926+
instantiateInUnion(tp.tp1)
1927+
instantiateInUnion(tp.tp2)
1928+
case tp: FlexibleType =>
1929+
instantiateInUnion(tp.hi)
1930+
case tp: TypeVar =>
1931+
isFullyDefined(tp, ForceDegree.flipBottom)
1932+
case _ =>
1933+
1934+
if untpd.isFunctionWithUnknownParamType(tree) && !calleeType.exists then
19271935
// try to instantiate `pt` if this is possible. If it does not
19281936
// work the error will be reported later in `inferredParam`,
19291937
// when we try to infer the parameter type.
1930-
isFullyDefined(pt, ForceDegree.flipBottom)
1938+
instantiateInUnion(pt)
19311939

19321940
val (protoFormals, resultTpt) = decomposeProtoFunction(pt, params.length, tree.srcPos)
19331941

0 commit comments

Comments
 (0)