Skip to content

Commit 7ce8e53

Browse files
committed
Make preCheckKinds convention more robust
An empty type bounds as a signal to suppress checking does not work if the argument type is higher-kinded. Using NoType avoids this problem.
1 parent 9dca57b commit 7ce8e53

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ object Checking {
108108
* in order to prevent scenarios that lead to self application of
109109
* types. Self application needs to be avoided since it can lead to stack overflows.
110110
* Test cases are neg/i2771.scala and neg/i2771b.scala.
111+
* A NoType paramBounds is used as a sign that checking should be suppressed.
111112
*/
112-
def preCheckKind(arg: Tree, paramBounds: TypeBounds)(implicit ctx: Context): Tree =
113-
if (arg.tpe.widen.isRef(defn.NothingClass) || arg.tpe.hasSameKindAs(paramBounds.hi)) arg
113+
def preCheckKind(arg: Tree, paramBounds: Type)(implicit ctx: Context): Tree =
114+
if (arg.tpe.widen.isRef(defn.NothingClass) ||
115+
!paramBounds.exists ||
116+
arg.tpe.hasSameKindAs(paramBounds.bounds.hi)) arg
114117
else errorTree(arg, em"Type argument ${arg.tpe} has not the same kind as its bound $paramBounds")
115118

116-
def preCheckKinds(args: List[Tree], paramBoundss: List[TypeBounds])(implicit ctx: Context): List[Tree] = {
119+
def preCheckKinds(args: List[Tree], paramBoundss: List[Type])(implicit ctx: Context): List[Tree] = {
117120
val args1 = args.zipWithConserve(paramBoundss)(preCheckKind)
118121
args1 ++ args.drop(paramBoundss.length)
119122
// add any arguments that do not correspond to a parameter back,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ class Typer extends Namer
12361236
case (tparam, TypeBoundsTree(EmptyTree, EmptyTree)) =>
12371237
// if type argument is a wildcard, suppress kind checking since
12381238
// there is no real argument.
1239-
TypeBounds.empty
1239+
NoType
12401240
case (tparam, _) =>
12411241
tparam.paramInfo.bounds
12421242
}

0 commit comments

Comments
 (0)