Closed ryan-williams closed 4 years ago
Thanks for submitting, @ryan-williams! Running this in a 2.12.2 REPL I get a bunch of warnings which rather give the game away :-(
scala> def test(o: obj) =
| o match {
| case one => 1
| case two => 2
| }
<console>:14: warning: patterns after a variable pattern cannot match (SLS 8.1.1
)
case one => 1
^
<console>:15: warning: unreachable code due to variable pattern 'one' on line 14
case two => 2
^
<console>:15: warning: unreachable code
case two => 2
^
test: (o: obj)Int
Do you have any thoughts on ways to get around them?
haha yea… I think I was running tests in IntelliJ and not seeing the compiler warnings when this bit me!
or I was ignoring compiler warnings due to a deluge of a pure expression does nothing in statement position
warnings from tests of implicit derivations like these
Feel free to close if that is the protocol 😄 thanks!
Feel free to close if that is the protocol
There's no strict protocol as such, but it's generally nicer to "hide" something in such a way that the compiler doesn't point out the issue, if possible.
Of course, given the amount of warnings that the average project tends to produce, "hiding in plain sight" is very much a valid tactic in some sense ;-)
There ought to be a lint for bare case x =>
, where it would not warn on case x @ _ =>
. For unused pattern vars, it already distinguishes these two forms. The lint would trigger if there is an x
in scope, much as missing interpolator is triggered "$x"
.
Closing this out for now - please re-open if we can come up with a suggestion on how to "hide" the warnings!
072
since idk if #153 still has the lock on it