Skip to content

Commit 09fad43

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 cbaa827 commit 09fad43

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
@@ -1254,7 +1254,7 @@ class Typer extends Namer
12541254
case (tparam, TypeBoundsTree(EmptyTree, EmptyTree)) =>
12551255
// if type argument is a wildcard, suppress kind checking since
12561256
// there is no real argument.
1257-
TypeBounds.empty
1257+
NoType
12581258
case (tparam, _) =>
12591259
tparam.paramInfo.bounds
12601260
}

0 commit comments

Comments
 (0)