Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't patmat to extract type constructor from quoted type #11738

Closed
japgolly opened this issue Mar 15, 2021 · 3 comments · Fixed by #17362
Closed

Can't patmat to extract type constructor from quoted type #11738

japgolly opened this issue Mar 15, 2021 · 3 comments · Fixed by #17362
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@japgolly
Copy link
Contributor

Using 3.0.0-RC1, I'm trying to test whether a type is in the shape of F[A].

import scala.quoted.*

def blah[A](using Quotes, Type[A]): Expr[Unit] =
  Type.of[A] match
    case '[h *: t] => println(s"h = ${Type.show[h]}, t = ${Type.show[t]}") // ok
    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}") // error
    case _         =>
  '{()}

The tuple case works, no problem. The f[a] case doesn't compile and instead fails with:

[error] -- [E053] Type Error: /home/golly/projects/public/univeq/univeq/shared/src/main/scala-3/japgolly/univeq/internal/test.scala:6:11 
[error] 6 |    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}")
[error]   |           ^^^^
[error]   |           f$given1.Underlying does not take type parameters

[error] -- [E006] Not Found Error: /home/golly/projects/public/univeq/univeq/shared/src/main/scala-3/japgolly/univeq/internal/test.scala:6:69 
[error] 6 |    case '[f[a]]   => println(s"f = ${Type.show[f]}, a = ${Type.show[a]}")
[error]   |                                                                     ^
[error]   |                                                         Not found: type a
@japgolly
Copy link
Contributor Author

Hey @nicolasstucki , would you happen to know an alternative way of doing this? I'm a bit stuck looking for a workaround :(

@japgolly
Copy link
Contributor Author

Found workaround thanks to @smarter : use TypeRepr.of to get to tasty

@nicolasstucki
Copy link
Contributor

The root of the issue is that we have no way to infer or tell the kind of the type variable.

The alternative is to use a pattern on expressions. I tried it but hit some bug or limitation. I need to dig into it. Nevertheless, the idea is to do

'{ ??? : A } match
  case '{ type f[X] ; ??? : `f`[t] } =>

@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed area:metaprogramming labels Jun 2, 2022
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 16, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 17, 2023
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`] =>
```

In combination with scala#16907 it would also allow
```
case '[type f[X]; `f`] =>
case '[type f <: AnyKind; `f`] =>
```
and therefore solve scala#10864 and scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 17, 2023
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`] =>
```

In combination with scala#16907 it would also allow
```scala
case '[type f[X]; `f`] =>
case '[type f <: AnyKind; `f`] =>
```
and therefore solve scala#10864 and scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 17, 2023
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`] =>
```

In combination with scala#16907 it would also allow
```scala
case '[type f[X]; `f`] =>
case '[type f <: AnyKind; `f`] =>
```
and therefore solve scala#10864 and scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 21, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 28, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 2, 2023
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 scala#10864
Fixes scala#11738
@nicolasstucki nicolasstucki linked a pull request May 2, 2023 that will close this issue
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 2, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 2, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 3, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 3, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 4, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 8, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 12, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 23, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 31, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue May 31, 2023
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 scala#10864
Fixes scala#11738
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 7, 2023
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 scala#10864
Fixes scala#11738
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Projects
None yet
3 participants