Skip to content

Unhelpful error message when trying to use named extraction, when not matching case class or named tuple #23354

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wwbakker
Copy link
Contributor

Fixes #22903

Worked on together by @jan-pieter @nmcb @RoccoMathijn @thijsnissen and me.

PR should still be finished.

@som-snytt
Copy link
Contributor

The new message is emitted for

[E215] Pattern Match Error: tests/neg/named-tuples.scala:44:10

which is the unnamed tuple case in the failing test. I wonder if the text could say "this is not a named tuple".

Selector type Tuple does not define any named elements

I would be confused and say I thought they supported named tuples now.

The PR doesn't have the test from the OP.

The phrase "selector type" might be confusing. I think of selector match { case ... => } because it selects which case. I don't think of it to mean "whatever value is matched in a subpattern". (My usage may be naive.) In this case, it sounds like "mechanism".

In the OP, the selector expression was 3

+19 |    case ProductMatch(someName = x) => println (x) // error
+   |                      ^^^^^^^^^^^^
+   |                      Selector type CustomProduct does not define any named elements

I don't know if there is a term that is precise yet friendly.

@wwbakker wwbakker marked this pull request as draft June 11, 2025 21:01
@wwbakker
Copy link
Contributor Author

Thanks @som-snytt, we (@jan-pieter , @RoccoMathijn @nmcb ) have had another look and we think we have improved the logic and error message a bit.

Next up is adding and fixing tests, and optionally looking at the underlined text in the error message. My colleagues are currently looking into that.

… pattern

Co-authored-by: nmcb <[email protected]>
Co-authored-by: jan-pieter <[email protected]>
Co-authored-by: wwbakker <[email protected]>
Co-authored-by: thijsnissen <[email protected]>
Co-authored-by: RoccoMathijn <[email protected]>
@wwbakker wwbakker marked this pull request as ready for review June 13, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhelpful error message when using named patterns with custom selector type in extractor match
3 participants