Skip to content

inline together with private object might generate code that throws IllegalAccessError #12160

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
scf37 opened this issue Apr 20, 2021 · 2 comments · Fixed by #14889
Closed

inline together with private object might generate code that throws IllegalAccessError #12160

scf37 opened this issue Apr 20, 2021 · 2 comments · Fixed by #14889

Comments

@scf37
Copy link

scf37 commented Apr 20, 2021

Compiler version

3.0.0-RC3

Minimized code

https://github.com/scf37/fpscala2/tree/scala3-bug

checkout and run sbt run

Output

java.lang.IllegalAccessError: failed to access class tethys.readers.JsonReaderInternal$ProductArray$ from class me.scf37.fpscala2.controller.TodoRequest$ (tethys.readers.JsonReaderInternal$ProductArray$ and me.scf37.fpscala2.controller.TodoRequest$ are in unnamed module of loader 'app')

Expectation

Successful execution

@griggt
Copy link
Contributor

griggt commented Jul 17, 2021

A self-contained example:

import scala.deriving._

trait Show[A]:
  extension (a: A) def show: String

object Show:
  inline def derived[A](using m: Mirror.Of[A]): Show[A] = inline m match
    case p: Mirror.ProductOf[A] => internal.Shower.showProduct[A]
    case s: Mirror.SumOf[A] => ???

package internal:
  object Shower:
    inline def showProduct[A]: Show[A] =
      new Show[A] { extension (a: A) def show = P(a.toString).s }

    private case class P(str: String) { def s = str }  // must be a case class
end internal

case class Foo(s: String) derives Show

@main def Test =
  println(Foo("bar").show)
$ dotc -version
Scala compiler version 3.0.3-RC1-bin-SNAPSHOT-git-cc47c56 -- Copyright 2002-2021, LAMP/EPFL

$ dotc i12160.scala 
$ dotr Test
Exception in thread "main" java.lang.IllegalAccessError: tried to access class internal.Shower$P$ from class Foo$$anon$1
	at Foo$$anon$1.show(i12160.scala:14)
	at Foo$$anon$1.show(i12160.scala:14)
	at i12160$package$.Test(i12160.scala:22)
	at Test.main(i12160.scala:21)

@griggt griggt removed the stat:needs minimization Needs a self contained minimization label Jul 17, 2021
@nicolasstucki
Copy link
Contributor

Minimized to

package internal:
  object Foo:
    inline def foo: Unit = P.s

    private object P { def s = "b" }
end internal

@main def Test = internal.Foo.foo

@nicolasstucki nicolasstucki changed the title inline together with derives might generate code that throws IllegalAccessError inline together with private object might generate code that throws IllegalAccessError Jul 27, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 8, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Apr 8, 2022
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants