scala3
scala3 copied to clipboard
Cannot call an inline method that references a field from an anonymous class created with a transparent inline extension in 3.2.0
Compiler version
3.2.0, 3.2.2-RC1-bin-20220909-eaa2889-NIGHTLY
Minimized code
package repro
// this needs to be in a separate file, if placed in the same file then everything works
extension (src: String) {
// a new anonymous class is essential, it works as expected if this is just a constructor call
transparent inline def intoViaRepro = new TestClass(src) {}
}
package repro
class TestClass(source: String) {
inline def access = source
}
object Repro {
private val value = "whatever"
value.intoViaRepro.access
}
Output
[info] exception occurred while compiling ducktape/repro/src/main/scala/Repro.scala, ducktape/repro/src/main/scala/syntax.scala
java.lang.AssertionError: assertion failed: private value value in object Repro in ducktape/repro/src/main/scala/Repro.scala accessed from constructor $anon in ducktape/repro/src/main/scala/syntax.scala while compiling ducktape/repro/src/main/scala/Repro.scala, ducktape/repro/src/main/scala/syntax.scala
Expectation
The code compiles as it did in 3.1.3.
This can be worked around by doing this:
object Repro {
private val value = "whatever"
private def workaround(value: String) =
value.intoViaRepro.access
workaround(value)
}
Context
I've stumbled upon this error when compiling ducktape with Scala 3.2.0, the file that fails is located here, the class which needs a new anonymus instance here and the extension definition here.