Skip to content

Add regression tests #18240

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

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/neg-macros/i18228.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted.*

case class QueryMeta[T](map: Map[String, String])

object QueryMeta:
given [T]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:
def unapply(expr: Expr[QueryMeta[T]])(using q: Quotes): Option[QueryMeta[T]] =
import q.reflect.*
expr match
case '{ QueryMeta/*[T]*/(${ map }: Map[String, String]) } => // error: Reference to T within quotes requires a given scala.quoted.Type[T] in scope.
map.value.map(QueryMeta[T].apply)
case _ =>
None
13 changes: 13 additions & 0 deletions tests/pos-macros/i18228.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted.*

case class QueryMeta[T](map: Map[String, String])

object QueryMeta:
given [T: Type]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:
def unapply(expr: Expr[QueryMeta[T]])(using q: Quotes): Option[QueryMeta[T]] =
import q.reflect.*
expr match
case '{ QueryMeta[t](${ map }: Map[String, String]) } =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case '{ QueryMeta[t](${ map }: Map[String, String]) } =>
case '{ QueryMeta(${ map }: Map[String, String]) } =>

Shouldn't we use only either instance of Type[T] (variant a) or only type extractor [t] (variant b)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was supposed to be

        case '{ QueryMeta[T](${ map }: Map[String, String]) } =>

I pushed a fixed version.

map.value.map(QueryMeta[T].apply)
case _ =>
None
13 changes: 13 additions & 0 deletions tests/pos-macros/i18228b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted.*

case class QueryMeta[T](map: Map[String, String])

object QueryMeta:
given [T]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:
def unapply(expr: Expr[QueryMeta[T]])(using q: Quotes): Option[QueryMeta[T]] =
import q.reflect.*
expr match
case '{ QueryMeta[t](${ map }: Map[String, String]) } =>
map.value.map(QueryMeta[T].apply)
case _ =>
None