Skip to content
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