Skip to content

Warn if match in block is not used for PF #23002

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 1 commit into
base: main
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

Fixes #21649

Addresses the immediate user issue. (Confusion about compiler behavior.)

Follow-up is improve doc for PartialFunction and improve spec for pattern-matching anonymous function to include non-trivial selector expression.

Actually, first follow-up will be to address:

scala> def f: PartialFunction[(Int, Int), Int] = (x, y) => (2*x, y) match { case (x, y) if x < 5 => x + y }
1 warning found
-- [E210] Syntax Warning: ------------------------------------------------------
1 |def f: PartialFunction[(Int, Int), Int] = (x, y) => (2*x, y) match { case (x, y) if x < 5 => x + y }
  |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |match expression in result of block will not be used to synthesize partial function
  |
  | longer explanation available when compiling with `-explain`
def f: PartialFunction[(Int, Int), Int]

oh that's because of how parameters are untupled, no doubt. Compare

scala> def f: PartialFunction[(Int, Int), Int] = p => (2*p._1, p._2) match { case (x, y) if x < 5 => x + y }
def f: PartialFunction[(Int, Int), Int]

@som-snytt
Copy link
Contributor Author

footnote the syntax was aligned intentionally 8a91774 which is where I picked up the phrase non-trivial selector expression.

@som-snytt som-snytt marked this pull request as ready for review April 15, 2025 20:55
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.

Adding a useless assignment statement alters program behavior.
1 participant