Skip to content

ClassCastException when def is used for a type of a tracked val enum #23840

@kubukoz

Description

@kubukoz

Compiler version

3.7.2

Minimized code

//> using scala 3.7.2
import language.experimental.modularity

case class Event(tracked val payload: Payload)

enum Payload {
  case Created()
}

val e = Event(Payload.Created())

def handleCreated(e: Event { def payload : Payload.Created}) = println(e.payload)

@main def run = e match {
  case Event(payload: Payload.Created) => handleCreated(e.copy(payload = payload))
}

Output

Exception in thread "main" java.lang.ClassCastException: class Payload$Created cannot be cast to class scala.Function0 (Payload$Created and scala.Function0 are in unnamed module of loader 'app')
        at demo$package$.handleCreated(demo.scala:12)
        at demo$package$.run(demo.scala:15)
        at run.main(demo.scala:14)

Expectation

Either a compile error, or just Created() in the output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions