Skip to content

ClassCastException when using named pattern one single-component named tuple #23131

Open
@SrTobi

Description

@SrTobi

Compiler version

3.7.2-RC1-bin-20250507-c85982c-NIGHTLY

Minimized code

Some((name = "Bob")) match {
  case Some(name = a) => println(a)
}

Output

Compiles, but running the program gives:

Exception in thread "main" java.lang.ClassCastException: class scala.Tuple1 cannot be cast to class java.lang.String (scala.Tuple1 is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
	at org.test.Main$package$.test(Main.scala:17)
	at org.test.test.main(Main.scala:7)

Expectation

Should print 6

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:named-tuplesIssues tied to the named tuples feature.itype:bugitype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions