You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat tstar.scala
package tstar
object Test {
def foo1[T](t: T*) = println(t.toList)
def bar1[T](t: T) = foo1(t,t,t)
def foo2[@miniboxed T](t: T*) = println(t.toList)
def bar2[@miniboxed T](t: T) = foo2(t,t,t)
def main(args: Array[String]): Unit = {
bar1(false) // This should print List(false, false, false). It does.
bar2(false) // This should print List(false, false, false). It doesn't.
}
}
$ mb-scalac tstar.scala -P:minibox:warn-off
$ mb-scala tstar.Test
List(false, false, false)
List(0, 0, 0)
The underlying problem:
$ mb-scalac tstar.scala -Xprint:erasure
tstar.scala:12: warning: The method tstar.Test.bar1 would benefit from miniboxing type parameter T, since it is instantiated by a primitive type.
bar1(false) // This should print List(false, false, false). It does.
^
[[syntax trees at end of erasure]] // tstar.scala
package tstar {
object Test extends Object {
def <init>(): tstar.Test.type = {
Test.super.<init>();
()
};
def foo1(t: Seq): Unit = scala.this.Predef.println(t.toList());
def bar1(t: Object): Unit = Test.this.foo1(scala.this.Predef.genericWrapArray(Array[Object]{t, t, t}));
def foo2(t: Seq): Unit = scala.this.Predef.println(t.toList());
def foo2$n$D(T$TypeTag: Byte, t: Seq): Unit = scala.this.Predef.println(t.toList());
def foo2$n$J(T$TypeTag: Byte, t: Seq): Unit = scala.this.Predef.println(t.toList());
def bar2(t: Object): Unit = Test.this.foo2(scala.this.Predef.genericWrapArray(Array[Object]{t, t, t}));
def bar2$n$D(T$TypeTag: Byte, t: Double): Unit = Test.this.foo2$n$D(T$TypeTag, scala.this.Predef.genericWrapArray(Array[Double]{t, t, t}));
def bar2$n$J(T$TypeTag: Byte, t: Long): Unit = Test.this.foo2$n$J(T$TypeTag, scala.this.Predef.genericWrapArray(Array[Long]{t, t, t}));
def main(args: Array[String]): Unit = {
Test.this.bar1(scala.Boolean.box(false));
Test.this.bar2$n$J(1, MiniboxConversions.this.boolean2minibox(false))
}
}
}
one warning found
The underlying problem:
Specifically:
Which should have been:
The text was updated successfully, but these errors were encountered: