Skip to content

Commit 0665c4f

Browse files
authored
Merge pull request #1656 from dotty-staging/fix-#1652
Fix #1652: Make assertion more robust
2 parents 6ba6ea5 + 372140c commit 0665c4f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,11 @@ object Types {
25272527
case _: MethodType => true
25282528
case _ => false
25292529
}
2530+
2531+
/** Is this polytype a higher-kinded type lambda as opposed to a polymorphic?
2532+
* method type? Only type lambdas get created with variances, that's how we can tell.
2533+
*/
2534+
def isTypeLambda: Boolean = variances.nonEmpty
25302535

25312536
/** PolyParam references to all type parameters of this type */
25322537
lazy val paramRefs: List[PolyParam] = paramNames.indices.toList.map(PolyParam(this, _))
@@ -2914,9 +2919,15 @@ object Types {
29142919
def instantiate(fromBelow: Boolean)(implicit ctx: Context): Type = {
29152920
val inst = ctx.typeComparer.instanceType(origin, fromBelow)
29162921
if (ctx.typerState.isGlobalCommittable)
2917-
assert(!inst.isInstanceOf[PolyParam], i"bad inst $this := $inst, constr = ${ctx.typerState.constraint}")
2918-
// If this fails, you might want to turn on Config.debugCheckConstraintsClosed
2919-
// to help find the root of the problem.
2922+
inst match {
2923+
case inst: PolyParam =>
2924+
assert(inst.binder.isTypeLambda, i"bad inst $this := $inst, constr = ${ctx.typerState.constraint}")
2925+
// If this fails, you might want to turn on Config.debugCheckConstraintsClosed
2926+
// to help find the root of the problem.
2927+
// Note: Parameters of type lambdas are excluded from the assertion because
2928+
// they might arise from ill-kinded code. See #1652
2929+
case _ =>
2930+
}
29202931
instantiateWith(inst)
29212932
}
29222933

tests/neg/i1652.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
val v: Array[Array[Array]] = Array() // error // error
3+
def f[T](w: Array[Array[T]]) = { for (r <- w) () }
4+
f(v) // error
5+
}

0 commit comments

Comments
 (0)