Skip to content

Commit f3873aa

Browse files
committed
Avoid generating kind-incorrect types for wildcard arguments.
When doing the changes to higher-kinded types, an error popped up in pos/i3976.scala that a wildcard argument `_` was illegal because the corresponding type parameter is higher-kinded. This seemed to have been masked by an incorrect subtype check before. We now use the parameter bounds as the argument in this case.
1 parent dcdcd86 commit f3873aa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,24 @@ class Typer extends Namer
12331233
tparam.ensureCompleted() // This is needed to get the test `compileParSetSubset` to work
12341234
case _ =>
12351235
}
1236-
if (desugaredArg.isType) typed(desugaredArg, argPt)
1236+
if (desugaredArg.isType) {
1237+
var res = typed(desugaredArg, argPt)
1238+
arg match {
1239+
case TypeBoundsTree(EmptyTree, EmptyTree)
1240+
if tparam.paramInfo.isHK &&
1241+
tpt1.tpe.typeParamSymbols.nonEmpty &&
1242+
!ctx.mode.is(Mode.Pattern) =>
1243+
// An unbounded `_` automatically adapts to type parameter bounds. This means:
1244+
// If we have wildcard application C[_], where `C` is a class replace
1245+
// with C[_ >: L <: H] where `L` and `H` are the bounds of the corresponding
1246+
// type parameter in `C`, avoiding any referemces to parameters of `C`.
1247+
// The transform does not apply for patters, where empty bounds translate to
1248+
// wildcard identifiers `_` instead.
1249+
res = res.withType(avoid(tparam.paramInfo, tpt1.tpe.typeParamSymbols))
1250+
case _ =>
1251+
}
1252+
res
1253+
}
12371254
else desugaredArg.withType(UnspecifiedErrorType)
12381255
}
12391256
args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]

0 commit comments

Comments
 (0)