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

Type bound is not inferred inside quotation (type variable escapes?) #16121

Open
DmytroMitin opened this issue Sep 28, 2022 · 0 comments
Open
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug

Comments

@DmytroMitin
Copy link

DmytroMitin commented Sep 28, 2022

Compiler version

3.1.3
3.2.2-RC1-bin-20220925-562ab85-NIGHTLY

Minimized code

import scala.quoted.*

object Macro {
  inline def fooMacro[A, B]: Unit = ${fooMacroImpl[A, B]}

  def fooMacroImpl[A: Type, B: Type](using Quotes): Expr[Unit] = {
    import quotes.reflect.*

    val res = '{tag[A, B]} match {
      case '{
          type a
          type b <: `a`
          tag[`a`, `b`]
        } => '{foo[a, b]}
    }

    println(res.show)

    res
  }

  def tag[A, B] = ???

  def foo[A, B <: A]: Unit = ???
}

Output

Type argument b does not conform to upper bound a
        } => '{foo[a, b]}

Expectation

The macro should typecheck.

Comment

If I replace => '{foo[a, b]} with => '{foo[a, b & a]} then Macro.fooMacro[AnyVal, Int] typechecks but prints

Macro.foo[scala.AnyVal | b, scala.&[scala.Int, scala.AnyVal | b]]

instead of

Macro.foo[scala.AnyVal, scala.&[scala.Int, scala.AnyVal]]

Can be similar to

#13527

#14708

Motivated by https://stackoverflow.com/questions/70311751/what-scala-3-syntax-can-match-on-a-type-and-its-type-parameters-in-the-context-o

@DmytroMitin DmytroMitin added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 28, 2022
@dwijnand dwijnand added 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 Sep 29, 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