@@ -1606,32 +1606,31 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16061606 if desugared.isEmpty then
16071607 val inferredParams : List [untpd.ValDef ] =
16081608 for ((param, i) <- params.zipWithIndex) yield
1609- val (formalBounds, isErased) = protoFormal(i)
1610- val param0 =
1611- if (! param.tpt.isEmpty) param
1612- else
1613- val formal = formalBounds.loBound
1614- val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing
1615- val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1616- // If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound,
1617- // try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala)
1618- val paramType =
1619- // Strip inferred erased annotation, to avoid accidentally inferring erasedness
1620- val formal0 = if ! isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot ) else formal
1621- if knownFormal && ! isBottomFromWildcard then
1622- formal0
1623- else
1624- inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse(
1625- if knownFormal then formal0
1626- else errorType(AnonymousFunctionMissingParamType (param, tree, inferredType = formal, expectedType = pt), param.srcPos)
1627- )
1628- val paramTpt = untpd.TypedSplice (
1629- (if knownFormal then InferredTypeTree () else untpd.TypeTree ())
1630- .withType(paramType.translateFromRepeated(toArray = false ))
1631- .withSpan(param.span.endPos)
1609+ if (! param.tpt.isEmpty) param
1610+ else
1611+ val (formalBounds, isErased) = protoFormal(i)
1612+ val formal = formalBounds.loBound
1613+ val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing
1614+ val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1615+ // If the expected formal is a TypeBounds wildcard argument with Nothing as lower bound,
1616+ // try to prioritize inferring from target. See issue 16405 (tests/run/16405.scala)
1617+ val paramType =
1618+ // Strip inferred erased annotation, to avoid accidentally inferring erasedness
1619+ val formal0 = if ! isErased then formal.stripAnnots(_.symbol != defn.ErasedParamAnnot ) else formal
1620+ if knownFormal && ! isBottomFromWildcard then
1621+ formal0
1622+ else
1623+ inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse(
1624+ if knownFormal then formal0
1625+ else errorType(AnonymousFunctionMissingParamType (param, tree, inferredType = formal, expectedType = pt), param.srcPos)
16321626 )
1633- cpy.ValDef (param)(tpt = paramTpt)
1634- if isErased then param0.withAddedFlags(Flags .Erased ) else param0
1627+ val paramTpt = untpd.TypedSplice (
1628+ (if knownFormal then InferredTypeTree () else untpd.TypeTree ())
1629+ .withType(paramType.translateFromRepeated(toArray = false ))
1630+ .withSpan(param.span.endPos)
1631+ )
1632+ val param0 = cpy.ValDef (param)(tpt = paramTpt)
1633+ if isErased then param0.withAddedFlags(Flags .Erased ) else param0
16351634 desugared = desugar.makeClosure(Nil , inferredParams, fnBody, resultTpt, tree.span)
16361635
16371636 typed(desugared, pt)
0 commit comments