Skip to content

erased class used as parameter leads to runtime java.lang.NoSuchFieldError #23305

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

Open
mrdziuban opened this issue Jun 2, 2025 · 0 comments · May be fixed by #23311
Open

erased class used as parameter leads to runtime java.lang.NoSuchFieldError #23305

mrdziuban opened this issue Jun 2, 2025 · 0 comments · May be fixed by #23311

Comments

@mrdziuban
Copy link

Compiler version

3.6.4, 3.7.1, and latest nightly 3.7.2-RC1-bin-20250601-45ecc31-NIGHTLY

Minimized code

//> using scala 3.7.0
//> using options -language:experimental.erasedDefinitions

erased trait DBMeta[A]

trait Table[A]

case class Saved[A]()
object Saved {
  def table[A](using dbm: DBMeta[A]): Table[Saved[A]] = new Table[Saved[A]] {}
}

case class deleteBulk[A](as: List[Saved[A]])(using dbm: DBMeta[A], tbl: Table[A]) {
  final given savedTable: Table[Saved[A]] = Saved.table[A]
}

case class Foo()
object Foo {
  given dbMeta: DBMeta[Foo] = new DBMeta[Foo] {}
  given table: Table[Foo] = new Table[Foo] {}
}

val del = deleteBulk(List(Saved[Foo]()))
del.savedTable

Output

On the last line, del.savedTable, an exception is thrown:

java.lang.NoSuchFieldError: Class rs$line$1$deleteBulk does not have member field 'rs$line$1$DBMeta dbm'
	at rs$line$1$deleteBulk.savedTable$lzyINIT1(rs$line$1:11)
	at rs$line$1$deleteBulk.savedTable(rs$line$1:11)
	at rs$line$1$.<clinit>(rs$line$1:23)
	at rs$line$1.res0(rs$line$1)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at dotty.tools.repl.Rendering.$anonfun$4(Rendering.scala:120)
	at scala.Option.flatMap(Option.scala:283)
	at dotty.tools.repl.Rendering.valueOf(Rendering.scala:120)
	at dotty.tools.repl.Rendering.renderVal(Rendering.scala:160)
	at dotty.tools.repl.ReplDriver.$anonfun$8(ReplDriver.scala:415)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:334)
	at dotty.tools.repl.ReplDriver.extractAndFormatMembers$1(ReplDriver.scala:415)
	at dotty.tools.repl.ReplDriver.renderDefinitions$$anonfun$2(ReplDriver.scala:453)
	at scala.Option.map(Option.scala:242)
	at dotty.tools.repl.ReplDriver.renderDefinitions(ReplDriver.scala:452)
	at dotty.tools.repl.ReplDriver.compile$$anonfun$2(ReplDriver.scala:357)
	at scala.util.Either.fold(Either.scala:197)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:339)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:298)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:216)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:219)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:253)
	at dotty.tools.repl.ReplDriver.runBody$$anonfun$1(ReplDriver.scala:227)
	at dotty.tools.runner.ScalaClassLoader$.asContext(ScalaClassLoader.scala:80)
	at dotty.tools.repl.ReplDriver.runBody(ReplDriver.scala:227)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:219)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:156)
	at dotty.tools.repl.Main$.main(Main.scala:7)
	at dotty.tools.repl.Main.main(Main.scala)

Expectation

There should be no references to the dbm: DBMeta[A] parameter generated in deleteBulk since DBMeta is erased.

@mrdziuban mrdziuban added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 2, 2025
@som-snytt som-snytt linked a pull request Jun 3, 2025 that will close this issue
@som-snytt som-snytt removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Jun 3, 2025
@som-snytt som-snytt self-assigned this Jun 3, 2025
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