Skip to content
New issue

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

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

Already on GitHub? # to your account

inlined match on tuple, and expanding with *: causes class cast exception at runtime #15302

Closed
rmgk opened this issue May 27, 2022 · 2 comments · Fixed by #15330
Closed

inlined match on tuple, and expanding with *: causes class cast exception at runtime #15302

rmgk opened this issue May 27, 2022 · 2 comments · Fixed by #15330
Assignees
Milestone

Comments

@rmgk
Copy link

rmgk commented May 27, 2022

Compiler version

3.1.3-RC4, 3.2.0-RC1-bin-20220526-1ea177d-NIGHTLY-git-1ea177d

Minimized code

inline def flatConcat2[A, B](a: A, b: B) =
  b match
    case bs: *:[bh, bt]  => a *: bs

val x: (Int, Int, Int) = flatConcat2(1, (2,3))

Output

java.lang.ClassCastException: class scala.Tuple3 cannot be cast to class scala.Tuple1 (scala.Tuple3 and scala.Tuple1 are in unnamed module of loader sbt.internal.ScalaLibraryClassLoader @3401c1d7)
pointing to the end of the flatConcat2 definition

Expectation

This works if the inline is removed
Should not throw a ClassCastException.

Note, the match type of the def is:

type FlatConcat2[A, B] = B match
  case b *: bs => A *: b *: bs

but adding that does not change anything

@rmgk rmgk added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 27, 2022
@rmgk
Copy link
Author

rmgk commented May 27, 2022

Further minimization:

inline def test[B](b: B) =
  b match
    case b: Tuple => 1 *: b


test((1, 2))

@rmgk rmgk changed the title inlined match on tuples causes class cast exception at runtime inlined match on tuple, and expanding with *: causes class cast exception at runtime May 27, 2022
@szymon-rd szymon-rd added area:pattern-matching area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 30, 2022
@nicolasstucki
Copy link
Contributor

It seems to be a bug with the erasure of the type Int *: ((Int, Int) & bh *: bt) which is erased as Tuple1

@nicolasstucki nicolasstucki self-assigned this May 30, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 30, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 2, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 2, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants