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

ClassCastException (ArraySeq) when pattern-matching on varargs case class #11476

Closed
cheeseng opened this Issue Apr 8, 2019 · 6 comments

Comments

Projects
None yet
6 participants
@cheeseng
Copy link

commented Apr 8, 2019

We encounter a weird ClassCastException when running our tests in ScalaTest for org.scalactic.Every, that looks like this:

[error] (run-main-0) java.lang.ClassCastException: scala.collection.immutable.ArraySeq$ofInt cannot be cast to com.test.Every
[error] java.lang.ClassCastException: scala.collection.immutable.ArraySeq$ofInt cannot be cast to com.test.Every
[error] 	at com.test.TestMain$.main(TestMain.scala:7)
[error] 	at com.test.TestMain.main(TestMain.scala)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.lang.reflect.Method.invoke(Method.java:498)
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1

I tried to minimize the problem but not quite successful, the best I can do is to include the source of Every as com.test.Every, in the attached zip (a sbt project), you can reproduce the problem by running:

> sbt run

If you change the scala version to 2.12.8, it works without problem.

test-bug.zip

@Jasper-M

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

This is ... interesting.

scala> case class Foo(a: Int*) { def lengthCompare(i: Int) = 1 }
defined class Foo

scala> Foo(1) match { case Foo(a) => a }
java.lang.ClassCastException: scala.collection.immutable.ArraySeq$ofInt cannot be cast to Foo
  ... 36 elided
@eed3si9n

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

@Jasper-M Nice minimization.

@SethTisue SethTisue added this to the 2.13.0-RC2 milestone Apr 8, 2019

@SethTisue SethTisue changed the title Weird ClassCastException in ScalaTest's Every ClassCastException (ArraySeq) when pattern-matching on varargs case class Apr 8, 2019

@SethTisue

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

culprit guess, is it scala/scala#7068? (refs #11040)

note that this isn't an RC1 regression; it was broken in M5 too

@adriaanm suspects https://github.com/scala/scala/pull/7068/files#diff-352de7f9c77a7e21df6940d6a1bcdc7eR574

@eed3si9n wonders if scala/scala#6485 is also related

@SethTisue

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

@cheeseng is this hard to work around in your codebase? wondering how much of a 2.13 blocker it is

@adriaanm

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

@cheeseng

This comment has been minimized.

Copy link
Author

commented Apr 9, 2019

@SethTisue Not really a blocker, we just want to understand the reason behind tests failing under 2.13, and this is one of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.