Open
Description
Community build regression for https://github.com/ciaraobrien/dottytags (maintainer @CiaraOBrien)
Based on Open Community Build #1858
Part of #15647 regressions tracker
Compiler version
Works with 3.1.0
Fails in 3.1.1
Fails in 3.2.1-RC1-bin-20220712-7e20b81-NIGHTLYon` instead).
Minimized code
package dottytags
import scala.quoted.*
class TagClass private[dottytags] (val name: String)
private[dottytags] object TagClass:
def apply(name: String): TagClass = new TagClass(name)
inline def tag(inline name: String): TagClass = ${ tagClassMacro('name) }
private def tagClassMacro(nameExpr: Expr[String])(using Quotes): Expr[TagClass] = {
val tgExpr = Expr(TagClass(nameExpr.value.get))
TagClassFromExpr.unapply(tgExpr).foreach(println) // To trigger failure
tgExpr
}
private given TagClassFromExpr: FromExpr[TagClass] with
def unapply(x: Expr[TagClass])(using Quotes): Option[TagClass] =
x match
case '{ TagClass(${ Expr(name: String) }) } =>
println(s"in apply, name=$name)")
Some(TagClass(name))
case _ =>
import quotes.reflect.report
report.error(s"Failed to extract value from ${x.show}")
None
private given TagClassToExpr: ToExpr[TagClass] with
def apply(x: TagClass)(using Quotes): Expr[TagClass] = '{ TagClass(${ Expr(x.name) }) }
// usage.scala
import dottytags.*
@main def Test() = println(tag("html"))
Output
-- Error: test.scala:4:13 -------------------------------------------------------------------------------------------------------
4 | println(tag("html"))
| ^^^^^^^^^^^
| Failed to extract value from dottytags.macro$package.inline$TagClass.apply("html")
1 error found
Expectation
Compiles with the same output as in 3.1.0:
in apply, name=html)
dottytags.TagClass@5b3a8bea