Skip to content

Commit ffa9dcc

Browse files
committed
Fix false negatives
Special provisions need to be made if the type argument is a wildcard or of type Nothing.
1 parent 198a6c7 commit ffa9dcc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ object Checking {
110110
* Test cases are neg/i2771.scala and neg/i2771b.scala.
111111
*/
112112
def preCheckKind(arg: Tree, paramBounds: TypeBounds)(implicit ctx: Context): Tree =
113-
if (arg.tpe.hasSameKindAs(paramBounds.hi)) arg
113+
if (arg.tpe.widen.isRef(defn.NothingClass) || arg.tpe.hasSameKindAs(paramBounds.hi)) arg
114114
else errorTree(arg, em"Type argument ${arg.tpe} has not the same kind as its bound $paramBounds")
115115

116116
def preCheckKinds(args: List[Tree], paramBoundss: List[TypeBounds])(implicit ctx: Context): List[Tree] = {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,16 +1131,23 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11311131
if (tpt1.symbol.isClass)
11321132
tparam match {
11331133
case tparam: Symbol =>
1134-
// This is needed to get the test `compileParSetSubset` to work
1135-
tparam.ensureCompleted()
1134+
tparam.ensureCompleted() // This is needed to get the test `compileParSetSubset` to work
11361135
case _ =>
11371136
}
11381137
if (desugaredArg.isType) typed(desugaredArg, argPt)
11391138
else desugaredArg.withType(UnspecifiedErrorType)
11401139
}
11411140
args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]
11421141
}
1143-
val args2 = preCheckKinds(args1, tparams.map(_.paramInfo.bounds))
1142+
val paramBounds = (tparams, args).zipped.map {
1143+
case (tparam, TypeBoundsTree(EmptyTree, EmptyTree)) =>
1144+
// if type argument is a wildcard, suppress kind checking since
1145+
// there is no real argument.
1146+
TypeBounds.empty
1147+
case (tparam, _) =>
1148+
tparam.paramInfo.bounds
1149+
}
1150+
val args2 = preCheckKinds(args1, paramBounds)
11441151
// check that arguments conform to bounds is done in phase PostTyper
11451152
assignType(cpy.AppliedTypeTree(tree)(tpt1, args2), tpt1, args2)
11461153
}

0 commit comments

Comments
 (0)