Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VarArgs transformation error #230

Open
VladUreche opened this issue Jun 5, 2015 · 0 comments
Open

VarArgs transformation error #230

VladUreche opened this issue Jun 5, 2015 · 0 comments
Assignees
Milestone

Comments

@VladUreche
Copy link
Member

$ 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

Specifically:

    def bar2$n$D(T$TypeTag: Byte, t: Double): Unit = 
      foo2$n$D(T$TypeTag, Predef.genericWrapArray(Array[Double]{t, t, t}));
    def bar2$n$J(T$TypeTag: Byte, t: Long): Unit = 
      foo2$n$J(T$TypeTag, Predef.genericWrapArray(Array[Long]{t, t, t}));

Which should have been:

    def bar2$n$D(T$TypeTag: Byte, t: Double): Unit = 
      foo2$n$D(T$TypeTag, Predef.genericWrapArray(Array[Object]{minibox2box(t), ...}));
    def bar2$n$J(T$TypeTag: Byte, t: Long): Unit = 
      foo2$n$J(T$TypeTag, Predef.genericWrapArray(Array[Object]{minibox2box(t), ...}));
@VladUreche VladUreche added this to the 0.4 milestone Jun 5, 2015
@VladUreche VladUreche self-assigned this Jun 5, 2015
@VladUreche VladUreche changed the title VarArgs typing error VarArgs transformation error Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant