Skip to content

Bad symbol is selected leading to ClassCastException. Regression from scala 2.13 #19711

Closed
@jtjeferreira

Description

@jtjeferreira

Compiler version

Scala 3.3.2 (3.4.0 also affected)

Minimized code

https://scastie.scala-lang.org/YdGomTp2S0Sc48M47mXLEA

case class Config(_config: String)

abstract class Foo(val config: Config) {
  def this(config: String) = {
    this(Config(config))
  }
}

class Bar(config: String) extends Foo(config) {
  def foo(): Unit = {
    config.getClass()
  }
}

new Bar("").foo() //This line will crash in prod

Output

Caused by: java.lang.ClassCastException: class Playground$Config cannot be cast to class java.lang.String (Playground$Config is in unnamed module of loader sbt.internal.BottomClassLoader @11415fc3; java.lang.String is in module java.base of loader 'bootstrap')
at Playground$Bar.config$accessor(main.scala:11)
	at Playground$Bar.foo(main.scala:13)
	at Playground$.<clinit>(main.scala:17)

Expectation

That code compiles and runs without crashing (like in scala 2.13)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions