Skip to content
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

matching on objects with lower-case first letters #154

Closed
wants to merge 1 commit into from

Conversation

ryan-williams
Copy link

@demobox
Copy link
Collaborator

demobox commented Aug 8, 2018

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?

@ryan-williams
Copy link
Author

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!

@demobox
Copy link
Collaborator

demobox commented Aug 8, 2018

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 ;-)

@som-snytt
Copy link
Contributor

som-snytt commented Jan 15, 2020

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".

scala/bug#11850

@demobox
Copy link
Collaborator

demobox commented Aug 18, 2020

Closing this out for now - please re-open if we can come up with a suggestion on how to "hide" the warnings!

@demobox demobox closed this Aug 18, 2020
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.

None yet

3 participants