-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Quoted pattern matching does not work when quote is in a val. #16543
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
Comments
Related to #16533? |
The limitation here is that the We provide the users with the private def patImpl(e: Expr[Int])(using Quotes): Expr[String] = {
val Expr = '{ 3 }
if e.matches(Expr) then '{"ok"}
else '{"other"} Another way we could achieve it is to support splicing expressions into (as opposed to out of) a quoted pattern. |
I see, thanks! Maybe we could warn on use of == on Expr to let the user know about |
We can't just pattern match on it because of scala#16543.
We can't just pattern match on it because of scala#16543.
Compiler version
3.3.0-RC1-bin-20221215-ef653b6-NIGHTLY
Minimized code
After inlining,
pat(3)
is replaced by"ok"
as expected in the following code:But if I put the quote in a pattern, then I get "other" instead:
Expectation
I think ideally both code snippets should behave the same. My usecase is that I'd like to check if some expression is already present in the input, and if not output what code should be generated (cf https://contributors.scala-lang.org/t/scala-3-macro-annotations-and-code-generation/6035), so I'd like to write the Expr once and use it both for pattern matching and as an output.
The text was updated successfully, but these errors were encountered: