diff --git a/tests/neg-macros/i18228.scala b/tests/neg-macros/i18228.scala new file mode 100644 index 000000000000..8fcd8988abe8 --- /dev/null +++ b/tests/neg-macros/i18228.scala @@ -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 diff --git a/tests/pos-macros/i18228.scala b/tests/pos-macros/i18228.scala new file mode 100644 index 000000000000..f0b8226fc135 --- /dev/null +++ b/tests/pos-macros/i18228.scala @@ -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]) } => + map.value.map(QueryMeta[T].apply) + case _ => + None diff --git a/tests/pos-macros/i18228b.scala b/tests/pos-macros/i18228b.scala new file mode 100644 index 000000000000..977fc93e9846 --- /dev/null +++ b/tests/pos-macros/i18228b.scala @@ -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