Skip to content

matching on objects with lower-case first letters#154

Closed
ryan-williams wants to merge 1 commit into
scalapuzzlers:masterfrom
ryan-williams:lco
Closed

matching on objects with lower-case first letters#154
ryan-williams wants to merge 1 commit into
scalapuzzlers:masterfrom
ryan-williams:lco

Conversation

@ryan-williams

Copy link
Copy Markdown

@demobox

demobox commented Aug 8, 2018

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

demobox commented Aug 8, 2018

Copy link
Copy Markdown
Collaborator

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

som-snytt commented Jan 15, 2020

Copy link
Copy Markdown
Contributor

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

demobox commented Aug 18, 2020

Copy link
Copy Markdown
Collaborator

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.

3 participants