scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Trivial inline identity function causes runtime `NoClassDefFound` error in resulting code

Open neko-kai opened this issue 6 months ago • 1 comments

Compiler version

3.3.6, 3.7.0 and 3.7.1-RC2

Minimized code

inline def simpleInlineWrap(f: => Any): Unit = f

@main def main(): Unit = {
  simpleInlineWrap {
    object lifecycle {
      object Lifecycle {
        trait FromZIO
      }
    }
    object defn {
      val Lifecycle: lifecycle.Lifecycle.type = lifecycle.Lifecycle
    }
    val xa: defn.Lifecycle.type = defn.Lifecycle
  }
}

https://scastie.scala-lang.org/fcE9r7cwQBSw7m5XwrrR1w - Scastie running on 3.7.1-RC2

Output

java.lang.NoClassDefFoundError: main$package$_$lifecycle$Lifecycle$
	at main$package$.f$proxy1$1(main.scala:13)
	at main$package$.main(main.scala:4)
	at main.main(main.scala:3)

Expectation

Expected not to throw NoClassDefFound error. Removing inline from simpleInlineWrap causes the code to work as expected.

NB: encountered when using ScalaTest, which at some point started wrapping all user tests via inline functions

neko-kai avatar May 28 '25 20:05 neko-kai

The working case at flatten has

        val xa:
          i23279$package$lifecycle$2.this.i23279$package$lifecycle$2$Lifecycle
           = this.defn$1(defn$lzy1, lifecycle$lzy1).Lifecycle()

before flatten

        val xa: lifecycle$2.this.Lifecycle =
          this.defn$1(defn$lzy1, lifecycle$lzy1).Lifecycle()

The broken proxy has

        val xa: i23279$package.lifecycle.i23279$package$_$lifecycle$Lifecycle =
          this.defn$1(defn$lzy1, lifecycle$lzy1).Lifecycle().asInstanceOf[
            i23279$package.lifecycle.i23279$package$_$lifecycle$Lifecycle]

before flatten

        val xa: i23279$package.lifecycle.Lifecycle =
          this.defn$1(defn$lzy1, lifecycle$lzy1).Lifecycle().asInstanceOf[
            i23279$package.lifecycle.Lifecycle]

where it should be lifecycle$2 after lambdalift.

som-snytt avatar May 28 '25 21:05 som-snytt

@som-snytt Apologies for threading on your ground, but the issue seems pretty severe and I think I managed to find the fix (#23432). Thank you for the initial investigation here

jchyb avatar Jun 26 '25 11:06 jchyb