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

Macro quoted pattern matching fails when parnethesis added for typing: (${tl}: XYZ) #19946

Closed
hmf opened this issue Mar 14, 2024 · 1 comment
Closed
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label

Comments

@hmf
Copy link

hmf commented Mar 14, 2024

Compiler version

Version 3.4.0

Minimized code

File 1:

  transparent inline def expandMacro(inline from: Tuple): Any = 
    ${ expandMacroImpl }

  // see https://github.com/scala/scala3/issues/19941
  def expandMacroImpl(using Quotes): Expr[?] =
    // '{ 1 *: 2 *: EmptyTuple } match
    '{ 1 *: EmptyTuple } match
      // case '{ 1 *: EmptyTuple} =>
      //   '{ ICons("7", 7, IEmpT) }
      // case '{ type e <: Int ; $e: e *: EmptyTuple} =>
      //   '{ ICons("6", 6, IEmpT) }
      // case '{ $hd: Int *: EmptyTuple} =>
      //   '{ ICons("5", 5, IEmpT) }
      // case '{ type t <: Tuple; $hd: Int *: EmptyTuple} =>
      //   '{ ICons("4", 4, IEmpT) }
      // case '{ type t <: Tuple; $hd: h *: EmptyTuple} =>
      //   '{ ICons("4", 4, IEmpT) }
      // case '{ type t <: Tuple; $hd: h *: t} =>
      //   '{ ICons("4", 4, IEmpT) }
      case '{ ($hd: h) *: EmptyTuple} =>
        '{ ICons("3", 3, IEmpT) }
      case '{ ($hd: h) *: ($tl: EmptyTuple)} =>
        '{ ICons("3", 3, IEmpT) }
      case '{ type t <: Tuple; ($hd: h) *: ($tl: t) } =>
        '{ ICons("2", 2, IEmpT) }
      case '{ type t <: Tuple; ($hd: h) *: ($tl: t) *: EmptyTuple} =>
        '{ ICons("1", 1, IEmpT) }
      // case '{ ${hd *: tl} : *:[h,t] } => 
      //    // Should not match
      //   '{ ICons("1", 1, IEmpT) }
      case _ =>
        '{IEmpT}

File 2:

    val r1 = expandMacro((1,2))
    summon[r1.type <:< ICons[String, Int, IEmpT.type]]

Output

Cannot prove that (r1 : data.Macros9.IEmpT.type) <:< data.Macros9.ICons[String, Int, data.Macros9.IEmpT.type].bloop(172)

Expectation

I would expect the match to work for the first uncommented case and for all others that follow. All other commented cases work. Note that this report follows from issue 19941 which determines that the last commented case should also not match but case '{ type t <: Tuple; ($hd: h) *: ($tl: t) } should, which it seems does not. The problem seems to be with the parenthesis used for enclosing the type.

@hmf hmf added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 14, 2024
@hmf
Copy link
Author

hmf commented Mar 14, 2024

Duplicate of #19947

@hmf hmf closed this as completed Mar 14, 2024
@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

No branches or pull requests

2 participants