Skip to content

Commit c451e47

Browse files
committed
Infer erasedness for desugared closure even if the type is known
1 parent 9ad78c0 commit c451e47

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,21 +1500,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15001500
if desugared.isEmpty then
15011501
val inferredParams: List[untpd.ValDef] =
15021502
for ((param, i) <- params.zipWithIndex) yield
1503-
if (!param.tpt.isEmpty) param
1504-
else
1505-
val (formal, isErased) = protoFormal(i)
1506-
val knownFormal = isFullyDefined(formal, ForceDegree.failBottom)
1507-
val paramType =
1508-
if knownFormal then formal
1509-
else inferredFromTarget(param, formal, calleeType, paramIndex)
1510-
.orElse(errorType(AnonymousFunctionMissingParamType(param, tree, formal), param.srcPos))
1511-
val paramTpt = untpd.TypedSplice(
1512-
(if knownFormal then InferredTypeTree() else untpd.TypeTree())
1513-
.withType(paramType.translateFromRepeated(toArray = false))
1514-
.withSpan(param.span.endPos)
1515-
)
1516-
val param1 = if isErased then param.withAddedFlags(Flags.Erased) else param
1517-
cpy.ValDef(param1)(tpt = paramTpt)
1503+
val (formal, isErased) = protoFormal(i)
1504+
val param0 =
1505+
if (!param.tpt.isEmpty) param
1506+
else
1507+
val knownFormal = isFullyDefined(formal, ForceDegree.failBottom)
1508+
val paramType =
1509+
if knownFormal then formal
1510+
else inferredFromTarget(param, formal, calleeType, paramIndex)
1511+
.orElse(errorType(AnonymousFunctionMissingParamType(param, tree, formal), param.srcPos))
1512+
val paramTpt = untpd.TypedSplice(
1513+
(if knownFormal then InferredTypeTree() else untpd.TypeTree())
1514+
.withType(paramType.translateFromRepeated(toArray = false))
1515+
.withSpan(param.span.endPos)
1516+
)
1517+
cpy.ValDef(param)(tpt = paramTpt)
1518+
if isErased then param0.withAddedFlags(Flags.Erased) else param0
15181519
desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span)
15191520

15201521
typed(desugared, pt)

0 commit comments

Comments
 (0)