Skip to content

Commit c6feafe

Browse files
authored
Merge pull request #6100 from dotty-staging/fix-#6064
Fix #6064: Hardening in the presence of kind mismatches
2 parents f59f2ba + 09ae674 commit c6feafe

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

compiler/src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ trait Substituters { this: Context =>
5858
val sym = tp.symbol
5959
var fs = from
6060
var ts = to
61-
while (fs.nonEmpty) {
61+
while (fs.nonEmpty && ts.nonEmpty) {
6262
if (fs.head eq sym) return ts.head
6363
fs = fs.tail
6464
ts = ts.tail
@@ -203,7 +203,7 @@ trait Substituters { this: Context =>
203203
val sym = tp.symbol
204204
var fs = from
205205
var ts = to
206-
while (fs.nonEmpty) {
206+
while (fs.nonEmpty && ts.nonEmpty) {
207207
if (fs.head eq sym)
208208
return ts.head match {
209209
case TypeBounds(lo, hi) => range(lo, hi)

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4791,10 +4791,7 @@ object Types {
47914791

47924792
case tp @ AppliedType(tycon, args) =>
47934793
@tailrec def foldArgs(x: T, tparams: List[ParamInfo], args: List[Type]): T =
4794-
if (args.isEmpty) {
4795-
assert(tparams.isEmpty)
4796-
x
4797-
}
4794+
if (args.isEmpty || tparams.isEmpty) x
47984795
else {
47994796
val tparam = tparams.head
48004797
val acc = args.head match {

tests/neg/i6063.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object i0 {
2+
trait I1[i0, I1]
3+
def I1[I1[I1]](I1: I1[ ; // error
4+
I1[I1]
5+
}
6+
7+
object test {
8+
object I0 {
9+
trait i2[I1, i2]
10+
def i2[i2[i2]](i2: i2[ ]) = i2 // error
11+
i2[i2]}
12+
}

tests/neg/i6064.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait Trait[X] {
2+
def f[C[_]](arg: C[X]): Int
3+
val a = f[(Int, String)] // error
4+
}

0 commit comments

Comments
 (0)