TypeTest for opaque type with wildcard argument #20430
tschuchortdev
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A
TypeTest
can be used with opaque type aliases or abstract type members to enable safe pattern matching. We can write a pattern match on an opaque type with a wildcard argument:Unfortunately, applying a wildcard type to an opaque type is illegal in all other places (in contrast to classes with type parameters, where you can legally apply wildcards for all parameters), so we can not actually provide a
TypeTest
specifically for a wildcard pattern match:It seems that the compiler will always translate the wildcard into a type
_ >: Nothing <: Any
regardless of the expected kind of the type parameter. The followingTypeTest
would be chosen here, but will cause a compiler crash (see #20429):For higher kinded opaque type aliases, no
TypeTest
would be chosen because the wildcard is of an illegal kind in that position (also see #20429).I think it would be very useful to be able to provide a
TypeTest
for types with wildcard arguments. My proposal is to translate the wildcard to the appropriately kinded least specific upper bound (Any
,[_] =>> Any
,[_[_]] =>> Any
, etc.) when looking for aTypeTest
. This should be pretty easy to implement and would also automatically fix #20429.Beta Was this translation helpful? Give feedback.
All reactions