Tighter condition for nowarn a single patvar #11048
Merged
+50
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address the question how liberal the exclusion for unused patvars should be.
This commit proposes: a single patvar named after the selector is always OK.
That is analogous to "narrow a var via a type pattern",
(x: Option[_]) match { case x: Some[_] => }
.This "ergonomics" respects "cut and paste" where patterns that don't have a "canonical" patvar name may represent "extract a canonically narrower value". It still requires the patvar name to "align" with the selector name.
The patvar is unused, but the match expression is allowed as something cut and pasted, so it's annoying to require "fixing up" just to pass a lint. The previous allowance is for case class element names,
case Person(firstName, lastName) =>
.At a
case
, it's not necessary to walk the pattern twice: it will processApply
before recursing into children, so childBind
will see the attachment.Fixes scala/scala-dev#902