@@ -1199,6 +1199,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1199
1199
1200
1200
/** Decompose function prototype into a list of parameter prototypes and a result
1201
1201
* prototype tree, using WildcardTypes where a type is not known.
1202
+ * Note: parameter prototypes may be TypeBounds.
1202
1203
* For the result type we do this even if the expected type is not fully
1203
1204
* defined, which is a bit of a hack. But it's needed to make the following work
1204
1205
* (see typers.scala and printers/PlainPrinter.scala for examples).
@@ -1234,7 +1235,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1234
1235
// if expected parameter type(s) are wildcards, approximate from below.
1235
1236
// if expected result type is a wildcard, approximate from above.
1236
1237
// this can type the greatest set of admissible closures.
1237
- (pt1.argTypesLo.init, typeTree(interpolateWildcards(pt1.argTypesHi.last)))
1238
+
1239
+ (pt1.argInfos.init, typeTree(interpolateWildcards(pt1.argInfos.last.hiBound)))
1238
1240
case RefinedType (parent, nme.apply, mt @ MethodTpe (_, formals, restpe))
1239
1241
if defn.isNonRefinedFunction(parent) && formals.length == defaultArity =>
1240
1242
(formals, untpd.DependentTypeTree (syms => restpe.substParams(mt, syms.map(_.termRef))))
@@ -1473,11 +1475,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1473
1475
}
1474
1476
1475
1477
var desugared : untpd.Tree = EmptyTree
1476
- if protoFormals.length == 1 && params.length != 1 && ptIsCorrectProduct(protoFormals.head) then
1477
- val isGenericTuple =
1478
- protoFormals.head.derivesFrom(defn.TupleClass )
1479
- && ! defn.isTupleClass(protoFormals.head.typeSymbol)
1480
- desugared = desugar.makeTupledFunction(params, fnBody, isGenericTuple)
1478
+ if protoFormals.length == 1 && params.length != 1 then
1479
+ val firstFormal = protoFormals.head.loBound
1480
+ if ptIsCorrectProduct(firstFormal) then
1481
+ val isGenericTuple =
1482
+ firstFormal.derivesFrom(defn.TupleClass )
1483
+ && ! defn.isTupleClass(firstFormal.typeSymbol)
1484
+ desugared = desugar.makeTupledFunction(params, fnBody, isGenericTuple)
1481
1485
else if protoFormals.length > 1 && params.length == 1 then
1482
1486
def isParamRef (scrut : untpd.Tree ): Boolean = scrut match
1483
1487
case untpd.Annotated (scrut1, _) => isParamRef(scrut1)
@@ -1499,12 +1503,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
1499
1503
for ((param, i) <- params.zipWithIndex) yield
1500
1504
if (! param.tpt.isEmpty) param
1501
1505
else
1502
- val formal = protoFormal(i)
1506
+ val formalBounds = protoFormal(i)
1507
+ val formal = formalBounds.loBound
1508
+ val isBottomFromWildcard = (formalBounds ne formal) && formal.isExactlyNothing
1503
1509
val knownFormal = isFullyDefined(formal, ForceDegree .failBottom)
1504
1510
// If the expected formal is Nothin, try to prioritize inferring from target,
1505
1511
// if possible. See issue 16405 (tests/run/16405.scala)
1506
1512
val paramType =
1507
- if knownFormal && ! formal.isExactlyNothing then
1513
+ if knownFormal && ! isBottomFromWildcard then
1508
1514
formal
1509
1515
else
1510
1516
val fromTarget = inferredFromTarget(param, formal, calleeType, paramIndex)
0 commit comments