Skip to content

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

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
SrTobi opened this issue May 9, 2025 · 3 comments
Open
Labels
area:named-tuples Issues tied to the named tuples feature. itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@SrTobi
Copy link
Contributor

SrTobi commented May 9, 2025

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

@SrTobi SrTobi added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 9, 2025
@SrTobi
Copy link
Contributor Author

SrTobi commented May 9, 2025

Interestingly this works fine:

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

@SrTobi
Copy link
Contributor Author

SrTobi commented May 9, 2025

Similar to #22900

@unkarjedy
Copy link
Contributor

We found it while providing the support for the feature for IntelliJ Scala Plugin

@xuwei-k xuwei-k added the area:named-tuples Issues tied to the named tuples feature. label May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:named-tuples Issues tied to the named tuples feature. itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

3 participants