Should we allow the `case ? =>` syntax for match types?
See original GitHub issueTo summarize the discussion in #12261:
-
There are 3 ways to write catch-all patterns for match types (
case _ =>
,case Any =>
, andcase ? =>
) -
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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So also disallow
case _: ? =>
, right?To be honest I find
case _: _ =>
confusingly unnecessary - does it have a use case?I think we should disallow
case ? =>
.?
should be allowed only as an argument to a type constructor.