A match type cannot be used as the result type of a pattern match involving extractor patterns #17845
Replies: 0 comments 5 replies
-
put another way |
Beta Was this translation helpful? Give feedback.
-
This is a missing feature, not a bug, the rules under which a pattern match can be typed with a match type are detailed in http://dotty.epfl.ch/docs/reference/new-types/match-types.html#dependent-typing which says in particular:
So extractor patterns are not supported. |
Beta Was this translation helpful? Give feedback.
-
@smarter can't complete adt matches like this be rewritten as a typed-pattern by the compiler? Is there some subtlety I'm missing, or is it just something that hasn't been implemented yet? |
Beta Was this translation helpful? Give feedback.
-
A lot of things can be implemented given enough time and energy, but I'll let @OlivierBlanvillain comment on the specifics :). I'll note that we only rewrite extractor patterns into type tests in the PatternMatcher phase which happens after typechecking. And the code that is of interest here is https://github.com/lampepfl/dotty/blob/a059dbc4c8185fecd003857e9d88c3ff43306322/compiler/src/dotty/tools/dotc/typer/Typer.scala#L1486-L1509 which does mention that this could be extended, so patches welcome I guess! |
Beta Was this translation helpful? Give feedback.
-
This is something that's on the roadmap (but lower priority than bug fixing). Your use case should be straightforward to support because // parts of what comes out of `case class Succ[N <: Nat](n: N) extends Nat`
object Succ {
def unapply(x$1: Succ): Succ = x$1
} |
Beta Was this translation helpful? Give feedback.
-
using scala 3.0.0
the following code compiles:
but if I change
def inc
to:I get:
I don't see how, for a sealed trait there is any difference in these matches. And since they should match the exact same values, why can't the compiler typecheck the second version, which is more natural.
This is very related to a previous bug report: #6709
Beta Was this translation helpful? Give feedback.
All reactions