@@ -1596,32 +1596,31 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15961596 if desugared.isEmpty then
15971597 val inferredParams : List [untpd.ValDef ] =
15981598 for ((param, i) <- params.zipWithIndex) yield
1599- val (formalBounds, isErased) = protoFormal(i)
1600- val param0 =
1601- if (! param.tpt.isEmpty) param
1602- else
1603- val formal = formalBounds.loBound
1604- val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing
1605- val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1606- // If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound,
1607- // try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala)
1608- val paramType =
1609- // Strip inferred erased annotation, to avoid accidentally inferring erasedness
1610- val formal0 = if ! isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot ) else formal
1611- if knownFormal && ! isBottomFromWildcard then
1612- formal0
1613- else
1614- inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse(
1615- if knownFormal then formal0
1616- else errorType(AnonymousFunctionMissingParamType (param, tree, formal), param.srcPos)
1617- )
1618- val paramTpt = untpd.TypedSplice (
1619- (if knownFormal then InferredTypeTree () else untpd.TypeTree ())
1620- .withType(paramType.translateFromRepeated(toArray = false ))
1621- .withSpan(param.span.endPos)
1599+ if (! param.tpt.isEmpty) param
1600+ else
1601+ val (formalBounds, isErased) = protoFormal(i)
1602+ val formal = formalBounds.loBound
1603+ val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing
1604+ val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1605+ // If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound,
1606+ // try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala)
1607+ val paramType =
1608+ // Strip inferred erased annotation, to avoid accidentally inferring erasedness
1609+ val formal0 = if ! isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot ) else formal
1610+ if knownFormal && ! isBottomFromWildcard then
1611+ formal0
1612+ else
1613+ inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse(
1614+ if knownFormal then formal0
1615+ else errorType(AnonymousFunctionMissingParamType (param, tree, formal), param.srcPos)
16221616 )
1623- cpy.ValDef (param)(tpt = paramTpt)
1624- if isErased then param0.withAddedFlags(Flags .Erased ) else param0
1617+ val paramTpt = untpd.TypedSplice (
1618+ (if knownFormal then InferredTypeTree () else untpd.TypeTree ())
1619+ .withType(paramType.translateFromRepeated(toArray = false ))
1620+ .withSpan(param.span.endPos)
1621+ )
1622+ val param0 = cpy.ValDef (param)(tpt = paramTpt)
1623+ if isErased then param0.withAddedFlags(Flags .Erased ) else param0
16251624 desugared = desugar.makeClosure(inferredParams, fnBody, resultTpt, isContextual, tree.span)
16261625
16271626 typed(desugared, pt)
0 commit comments