question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 (5a81d5aaea3862e58f2c6acbee76c67e8b3cce8b / 8968cc1124b08fb7cf452af0d496e4b8f49a6cfd)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dwijnandcommented, Jul 31, 2021

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

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

3reactions
oderskycommented, Jul 31, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Match Types - Scala 3 - EPFL
Subtyping Rules for Match Types​​ I.e. scrutinees and patterns must be equal and the corresponding bodies must be subtypes. No case re-ordering is...
Read more >
How to Use a match case Statement in Python 3.10
The match case statement in Python is more powerful and allows for more complicated pattern matching. Let's start by looking at a basic...
Read more >
Everything You Need To Know About Keyword Match Types
There are four different keyword match types for Google Ads: broad match, phrase match, exact match, and negative match. The image below shows ......
Read more >
About keyword matching options - Google Ads Help
Keywords are words or phrases that are used to match ads with the terms people are searching for. The keyword match types dictate...
Read more >
Match type syntax does not allow writing type patterns for ...
As I see it, the bigger issue is that the lack of syntax makes it seem as if it's impossible to do this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found