Skip to content

Class cast exception on inlined varargs #6858

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

Closed
nicolasstucki opened this issue Jul 16, 2019 · 1 comment
Closed

Class cast exception on inlined varargs #6858

nicolasstucki opened this issue Jul 16, 2019 · 1 comment

Comments

@nicolasstucki
Copy link
Contributor

Minimized code

object Test extends App {
  inline def foo(ys: Int*): Unit = Array(ys: _*)
  val xs = new Array[Int](3)
  foo(xs: _*)
}

fails with

Caused by: java.lang.ClassCastException: [I cannot be cast to scala.collection.Seq
	at Test$.<init>(foo.scala:5)
	at Test$.<clinit>(foo.scala)
	... 7 more

but adding an explicit type to xs makes it work

val xs: scala.collection.Seq[Int] = new Array[Int](3)

Expectation

The code should work

@nicolasstucki
Copy link
Contributor Author

There is a missing wrapIntArray call around xs in the inlining of foo.

We currently get

val xs: Array[Int] = new Array[Int](3)
    {
      val ys: Int* = this.xs:Int*
      this.bar(
        {
          ys
        }:Int*
      ):Unit
    }

where we should have

val xs: Array[Int] = new Array[Int](3)
    {
      val ys: Seq[Int] = wrapIntArray(this.xs)
      this.bar(
        {
          ys
        }:Int*
      ):Unit
    }

odersky added a commit that referenced this issue Jul 16, 2019
Fix #6858: Wrap array when passed to inlined varargs
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