Skip to content

Commit 08505bd

Browse files
committed
Workaround for SI-5583.
Somehow type args to be applied arrive in the specialized subclass where type args are no longer applicable. Log and discard.
1 parent f1c6714 commit 08505bd

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
13271327
}
13281328
} else super.transform(tree)
13291329

1330-
case TypeApply(Select(qual, name), targs)
1330+
case TypeApply(sel @ Select(qual, name), targs)
13311331
if (!specializedTypeVars(symbol.info).isEmpty && name != nme.CONSTRUCTOR) =>
13321332
debuglog("checking typeapp for rerouting: " + tree + " with sym.tpe: " + symbol.tpe + " tree.tpe: " + tree.tpe)
13331333
val qual1 = transform(qual)
@@ -1341,14 +1341,22 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
13411341
val residualTargs = symbol.info.typeParams zip targs collect {
13421342
case (tvar, targ) if !env.contains(tvar) || !isPrimitiveValueClass(env(tvar).typeSymbol) => targ
13431343
}
1344+
if (specMember.info.typeParams.isEmpty) {
1345+
// See SI-5583. Don't know why it happens now if it didn't before.
1346+
if (residualTargs.nonEmpty)
1347+
log("!!! Type args to be applied, but symbol says no parameters: " + ((specMember.defString, residualTargs)))
13441348

1345-
ifDebug(assert(residualTargs.length == specMember.info.typeParams.length,
1346-
"residual: %s, tparams: %s, env: %s".format(residualTargs, symbol.info.typeParams, env))
1347-
)
1349+
localTyper.typed(sel)
1350+
}
1351+
else {
1352+
ifDebug(assert(residualTargs.length == specMember.info.typeParams.length,
1353+
"residual: %s, tparams: %s, env: %s".format(residualTargs, specMember.info.typeParams, env))
1354+
)
13481355

1349-
val tree1 = gen.mkTypeApply(Select(qual1, specMember), residualTargs)
1350-
debuglog("rewrote " + tree + " to " + tree1)
1351-
localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method
1356+
val tree1 = gen.mkTypeApply(Select(qual1, specMember), residualTargs)
1357+
debuglog("rewrote " + tree + " to " + tree1)
1358+
localTyper.typedOperator(atPos(tree.pos)(tree1)) // being polymorphic, it must be a method
1359+
}
13521360

13531361
case None => super.transform(tree)
13541362
}

test/files/run/t5583.check

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Type in expressions to have them evaluated.
2+
Type :help for more information.
3+
4+
scala>
5+
6+
scala> var s = 0
7+
s: Int = 0
8+
9+
scala> for (i <- 1 to 10) {s += i}
10+
11+
scala> for (i <- 1 to 10) {s += i}
12+
13+
scala> for (i <- 1 to 10) {s += i}
14+
15+
scala> println(s)
16+
165
17+
18+
scala>
19+
20+
scala>

test/files/run/t5583.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.tools.partest.ReplTest
2+
3+
object Test extends ReplTest {
4+
def code = """
5+
var s = 0
6+
for (i <- 1 to 10) {s += i}
7+
for (i <- 1 to 10) {s += i}
8+
for (i <- 1 to 10) {s += i}
9+
println(s)
10+
"""
11+
}

0 commit comments

Comments
 (0)