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

Quote pattern not matching on *: #19947

Closed
nicolasstucki opened this issue Mar 14, 2024 · 2 comments · Fixed by #19948
Closed

Quote pattern not matching on *: #19947

nicolasstucki opened this issue Mar 14, 2024 · 2 comments · Fixed by #19948
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug
Milestone

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.4.0

Minimized code

import scala.quoted.*

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

def expandMacroImpl(using Quotes): Expr[?] =
  '{ 1 *: EmptyTuple } match
    case '{ type t <: Tuple; ($hd: h) *: ($tl: t) } => '{ ??? }
    case x => throw new MatchError(x.show)
def test: Any = expandMacro

Output

-- Error: t/Test2.scala:1:16 ---------------------------------------------------
1 |def test: Any = expandMacro
  |                ^^^^^^^^^^^
  |Exception occurred while executing macro expansion.
  |scala.MatchError: scala.Tuple$package.EmptyTuple.*:[scala.Int, scala.Tuple$package.EmptyTuple.type](1) (of class java.lang.String)
  |     at Test$package$.expandMacroImpl(Test.scala:9)
  |
  |-----------------------------------------------------------------------------
  |Inline stack trace
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |This location contains code that was inlined from Test.scala:4
4 |  ${ expandMacroImpl }
  |  ^^^^^^^^^^^^^^^^^^^^
   -----------------------------------------------------------------------------

Expectation

Should match

@nicolasstucki
Copy link
Contributor Author

Minimization

import scala.quoted.*

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

def expandMacroImpl(using Quotes): Expr[?] =
  '{ 1 *: EmptyTuple } match
    case '{ ($hd: Int) *: ($tl: Tuple) } => '{ ??? }
    case x => throw new MatchError(x.show)

@nicolasstucki
Copy link
Contributor Author

The pattern is typed as

case
  '{
    {
      val x$1: Int = ${hd @ _}:Int
      (${tl @ _}:Tuple).*:[Int, Tuple](x$1)
    }
  }
  =>

The val x$1 is probably the cause of this issue.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 14, 2024
nicolasstucki added a commit that referenced this issue Mar 19, 2024
In quoted patterns, we do not want to generate the val bindings. We care
about the original structure if the pattern expression.

Fixes #19947
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
WojciechMazur pushed a commit that referenced this issue Jul 3, 2024
WojciechMazur pushed a commit that referenced this issue Jul 3, 2024
WojciechMazur pushed a commit that referenced this issue Jul 3, 2024
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

Successfully merging a pull request may close this issue.

2 participants