Closed
Description
Compiler version
3.3.0, 3.3.1-RC3, 3.3.2-RC1-bin-20230710-ed319e8-NIGHTLY
Minimized code
//> using scala "3.3.1-RC3"
import scala.quoted.*
object ReproMacro {
inline def readPath[A, B](inline config: Config[A, B]) = ${ readPathMacro[A, B]('config) }
def readPathMacro[A: Type, B: Type](expr: Expr[Config[A, B]])(using Quotes) = {
import quotes.reflect.*
expr match {
case '{ Field.const[a, b, tpe]($selector) } =>
// the type of 'selector' is just a Expr[Function1[a, tpe]] instead of Expr[Selector ?=> Function1[a, tpe]]
val weirdInferredType: Expr[a => tpe] = selector
report.info(s"Matched!")
'{}
case other =>
report.errorAndAbort("woops, I did not match")
}
}
}
trait Selector {
extension [A](self: A) def at[B <: A]: B
}
trait Config[A, B]
object Field {
def const[A, B, FieldTpe](selector: Selector ?=> A => FieldTpe): Config[A, B] = ???
}
final case class Example(int: Int)
@main def main = {
// compiles just fine
ReproMacro.readPath[Example, Example](Field.const(_.int))
// doesn't compile
ReproMacro.readPath[Example, Example](Field.const(_.int.at[Int]))
}
Output
Compiling project (Scala 3.3.1-RC3, JVM)
[error] ./Field.scala:18:3: woops, I did not match
[error] ReproMacro.readPath[Example, Example](Field.const(_.int.at[Int]))
[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expectation
Both
ReproMacro.readPath[Example, Example](Field.const(_.int))
and
ReproMacro.readPath[Example, Example](Field.const(_.int.at[Int]))
should compile.