Skip to content

Should we allow the case ? => syntax for match types? #13223

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

Closed
OlivierBlanvillain opened this issue Jul 31, 2021 · 5 comments
Closed

Should we allow the case ? => syntax for match types? #13223

OlivierBlanvillain opened this issue Jul 31, 2021 · 5 comments

Comments

@OlivierBlanvillain
Copy link
Contributor

To summarize the discussion in #12261:

  • There are 3 ways to write catch-all patterns for match types (case _ =>, case Any =>, and case ? =>)

  • All of them are already in use in the community build (see case ? => in scodecs)

  • The current syntax is quite inconsistent:

    type A = _ // NOT OK
    type B = ? // NOT OK
    type M0[X] = X match { case ? => String } // OK
    type M1[X] = X match { case Any => _ }    // OK
    type M2[X] = X match { case Any => ? }    // OK
    val a = "" match { case _: _ => () }      // OK
    val b = try { } catch { case _: ? => () } // OK
  • Disallowing those standalone ? types would be a relative simple change to the parser (5a81d5a / 8968cc1)

@odersky
Copy link
Contributor

odersky commented Jul 31, 2021

I think we should disallow case ? => . ? should be allowed only as an argument to a type constructor.

@dwijnand
Copy link
Member

So also disallow case _: ? =>, right?

To be honest I find case _: _ => confusingly unnecessary - does it have a use case?

OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Aug 3, 2021
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Aug 4, 2021
@soronpo
Copy link
Contributor

soronpo commented Aug 11, 2021

Making sure. val ? = 1 and object ? are still allowed, yes?

OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Sep 22, 2021
OlivierBlanvillain added a commit to dotty-staging/dotty that referenced this issue Sep 22, 2021
@som-snytt
Copy link
Contributor

@dwijnand

scala> null match { case _ => }

scala> null match { case _: _ => }
scala.MatchError: null
  ... 30 elided

@dwijnand
Copy link
Member

Nice find. It's a case, but I can't think of how that has a use!

olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants