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

Matching bounded type parameter #16325

Open
prolativ opened this issue Nov 12, 2022 · 0 comments
Open

Matching bounded type parameter #16325

prolativ opened this issue Nov 12, 2022 · 0 comments
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@prolativ
Copy link
Contributor

Compiler version

3.3.0-RC1-bin-20221111-cc4c279-NIGHTLY and earlier

Minimized code

Macro.scala:

import scala.quoted.*

trait Container[A]
trait Box[A] extends Container[A]

class Wrapper[T <: Container[?]]

inline def qux0() = ${ qux0Impl }
def qux0Impl(using Quotes) =
  Type.of[Wrapper[Container[Int]]] match
    case '[Wrapper[x]] => '{}

inline def qux1() = ${ qux1Impl }
def qux1Impl(using Quotes) =
  Type.of[Wrapper[Box[Int]]] match
    case '[Wrapper[x]] => '{}

inline def qux2() = ${ qux2Impl }
def qux2Impl(using Quotes) =
  Type.of[Wrapper[Container[Int]]] match
    case '[Wrapper[Container[x]]] => '{}

Main.scala:

def q0 = qux0()
def q1 = qux1()
def q2 = qux2()

Output

The match in qux0Impl fails:

[error] Main.scala:1:10: Exception occurred while executing macro expansion.
[error] scala.MatchError: Type.of[...] (of class scala.quoted.runtime.impl.TypeImpl)
[error]         at Macro$package$.qux0Impl(Macro.scala:11)
[error] 
[error] def q0 = qux0()
[error]          ^^^^^^

If ? inside class Wrapper[T <: Container[?]] gets replaced with Int, then qux0Impl seems to work correctly but qux2Impl stops compiling, producing the error:

[error] Macro.scala:21:20: Type argument Container[x] does not conform to upper bound Container[Int]
[error]     case '[Wrapper[Container[x]]] => '{}
[error]                    ^

Expectation

All qux cases should compile in both variants (with class Wrapper[T <: Container[?]] or class Wrapper[T <: Container[Int]]), capturing the following types as x:

  • qux0 -> Container[Int]
  • qux1 -> Box[Int]
  • qux2 -> Int
@prolativ prolativ added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 12, 2022
@prolativ prolativ changed the title Matching bounded Matching bounded type parameter Nov 12, 2022
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
Development

No branches or pull requests

2 participants