Skip to content

Pattern matching type variable does not infer bounds #13527

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

Closed
KacperFKorban opened this issue Sep 14, 2021 · 1 comment
Closed

Pattern matching type variable does not infer bounds #13527

KacperFKorban opened this issue Sep 14, 2021 · 1 comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:enhancement

Comments

@KacperFKorban
Copy link
Member

KacperFKorban commented Sep 14, 2021

Compiler version

master

Minimized code

import scala.quoted.*

trait A:
  type B <: C
type C
def takesC[X <: C] = ???

def f(using Quotes) = {
  import quotes.reflect.*

  '{new A {}} match {
    case '{ $a : A { type B = b } } =>
      takesC[b]
  }
}

Output

-- [E057] Type Mismatch Error: tests/pos/type-bound-match.scala:13:13 --------------------------------------------------
13 |      takesC[b]
   |             ^
   |             Type argument b does not conform to upper bound C

Expectation

No error.

Workaround:

//...
  '{new A {}} match {
    case '{ type b <: C; $a : A { type B = `b` } } =>
      takesC[b]
  }
//...
@nicolasstucki nicolasstucki changed the title Pattern matching quoted type alias doesn't copy type bounds Pattern matching type variable does not infer bounds Sep 15, 2021
@nicolasstucki nicolasstucki added area:metaprogramming:quotes Issues related to quotes and splices and removed area:metaprogramming labels Feb 7, 2022
@nicolasstucki
Copy link
Contributor

We will not be able to infer the bounds of type variables. These should be stated explicitly.

Solution

case '{ type b <: C; $a : A { type B = b } } =>

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:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants