You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support type variable definitions in quoted patterns
Support explicit type variable definition in quoted patterns.
This allows users to set explicit bounds or use the binding twice.
Previously this was only possible on quoted expression patterns case '{ ... }.
```scala
case '[type x; x] =>
case '[type x; Map[x, x]] =>
case '[type x <: List[Any]; x] =>
case '[type f[X]; f] =>
case '[type f <: AnyKind; f] =>
```
Fixes#10864Fixes#11738
`Type.of[T]` is used to summon the given instance of `Type[T]` in scope, it is equivalent to `summon[Type[T]]`.
541
541
542
+
It is possible to match against a higer-kinded type using appropriate type bounds on type variables.
543
+
```scala
544
+
defempty[K<:AnyKind:Type]:Type[AnyKind] =
545
+
Type.of[K] match
546
+
case'[typef[X]; f] =>Type.of[f]
547
+
case'[typef[X<:Int, Y]; f] =>Type.of[f]
548
+
case'[typek<:AnyKind; k ] =>Type.of[k]
549
+
```
550
+
542
551
#### Type testing and casting
543
552
It is important to note that instance checks and casts on `Expr`, such as `isInstanceOf[Expr[T]]` and `asInstanceOf[Expr[T]]`, will only check if the instance is of the class `Expr` but will not be able to check the `T` argument.
544
553
These cases will issue a warning at compile-time, but if they are ignored, they can result in unexpected behavior.
0 commit comments