Skip to content

Commit be46e48

Browse files
committed
Fix for NoSuchMethod in cleanup.
Don't assume that just because someone is calling x.toInt and x <: java.lang.Number, that it's a boxed primitive. Closes SI-5356.
1 parent bedb33f commit be46e48

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,17 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
275275
/* ### HANDLING METHODS NORMALLY COMPILED TO OPERATORS ### */
276276

277277
val testForNumber: Tree => Tree = {
278-
qual1 => (qual1 IS_OBJ BoxedNumberClass.tpe) OR (qual1 IS_OBJ BoxedCharacterClass.tpe)
278+
// Can't shortcut on BoxedNumber because BoxesRunTime
279+
// is unforgiving of other Numbers showing up.
280+
qual1 => (
281+
(qual1 IS_OBJ BoxedIntClass.tpe)
282+
OR (qual1 IS_OBJ BoxedLongClass.tpe)
283+
OR (qual1 IS_OBJ BoxedDoubleClass.tpe)
284+
OR (qual1 IS_OBJ BoxedFloatClass.tpe)
285+
OR (qual1 IS_OBJ BoxedByteClass.tpe)
286+
OR (qual1 IS_OBJ BoxedShortClass.tpe)
287+
OR (qual1 IS_OBJ BoxedCharacterClass.tpe)
288+
)
279289
}
280290
val testForBoolean: Tree => Tree = {
281291
qual1 => (qual1 IS_OBJ BoxedBooleanClass.tpe)

test/files/run/t5356.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 scala.runtime.RichInt
2+
1 scala.runtime.RichInt
3+
1 scala.math.BigInt
4+
1 scala.runtime.RichDouble
5+
1 scala.runtime.RichFloat
6+
1

test/files/run/t5356.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
def f(x: { def toInt: Int }) = println(x.toInt + " " + x.getClass.getName)
3+
4+
def main(args: Array[String]): Unit = {
5+
f(1)
6+
f(1.toInt)
7+
f(BigInt(1))
8+
f(1d)
9+
f(1f)
10+
println((1: { def toInt: Int }).toInt)
11+
}
12+
}

0 commit comments

Comments
 (0)