Hello, I am trying to simply shift some macros using normal functions to the contexts ones. I have troubles with pattern matching context functions (is it even possible?)
trait Ctx
inline def patternMatchNoContext[T](inline body: Ctx => T): Ctx => T = ${ patternMatchNoContextImpl[T]('{ body }) }
def patternMatchNoContextImpl[T: Type](body: Expr[Ctx => T])(using quotes: Quotes): Expr[Ctx => T] =
body match
case '{ (context: Ctx) => $f(context): T } => f
inline def patternMatchContext[T](inline body: Ctx ?=> T): Ctx ?=> T = ${ patternMatchContextImpl[T]('{ body }) }
def patternMatchContextImpl[T: Type](body: Expr[Ctx ?=> T])(using Quotes): Expr[Ctx ?=> T] =
body match
case '{ (context: Ctx) ?=> $f(using context): T } => f
errors:
[48] [error] -- [E007] Type Mismatch Error: /Users/bkozak/IdeaProjects/macro3-z-bartusiem/GD3/4/src/commons/dupa.scala:12:74
[48] [error] 12 |inline def patternMatchContext[T](inline body: Ctx ?=> T): Ctx ?=> T = ${ patternMatchContextImpl[T]('{ body }) }
[48] [error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[48] [error] | Found: scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] | Required: scala.quoted.Expr[T]
[48] [error] |----------------------------------------------------------------------------
[48] [error] | Explanation (enabled by `-explain`)
[48] [error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[48] [error] |
[48] [error] | Tree: commons.patternMatchContextImpl[T](
[48] [error] | '{(using contextual$4: commons.Ctx) => body.apply(contextual$4)}.apply(
[48] [error] | contextual$3)
[48] [error] | )(scala.quoted.Type.of[T](contextual$3), contextual$3)
[48] [error] | I tried to show that
[48] [error] | scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] | conforms to
[48] [error] | scala.quoted.Expr[T]
[48] [error] | but none of the attempts shown below succeeded:
[48] [error] |
[48] [error] | ==> scala.quoted.Expr[(commons.Ctx) ?=> T] <: scala.quoted.Expr[T]
[48] [error] | ==> (commons.Ctx) ?=> T <: T
[48] [error] | ==> (commons.Ctx) ?=> T <: Nothing in frozen constraint = false
[48] [error] |
[48] [error] | The tests were made under a constraint with:
[48] [error] | uninstantiated variables:
[48] [error] | constrained types: [T](x: (scala.quoted.Quotes) ?=> scala.quoted.Expr[T]): T
[48] [error] | bounds:
[48] [error] | T := T
[48] [error] | ordering:
[48] [error] | co-deps:
[48] [error] | contra-deps:
[48] [error] ----------------------------------------------------------------------------
[48] [error] -- [E007] Type Mismatch Error: /Users/bkozak/IdeaProjects/macro3-z-bartusiem/GD3/4/src/commons/dupa.scala:15:57
[48] [error] 15 | case '{ (context: Ctx) ?=> $f(using context): T } => f
[48] [error] | ^
[48] [error] | Found: (f : scala.quoted.Expr[commons.Ctx => T])
[48] [error] | Required: scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] |----------------------------------------------------------------------------
[48] [error] | Explanation (enabled by `-explain`)
[48] [error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[48] [error] |
[48] [error] | Tree: f
[48] [error] | I tried to show that
[48] [error] | (f : scala.quoted.Expr[commons.Ctx => T])
[48] [error] | conforms to
[48] [error] | scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] | but none of the attempts shown below succeeded:
[48] [error] |
[48] [error] | ==> (f : scala.quoted.Expr[commons.Ctx => T]) <: scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] | ==> commons.Ctx => T <: (commons.Ctx) ?=> T = false
[48] [error] | ==> scala.quoted.Expr[commons.Ctx => T] <: scala.quoted.Expr[(commons.Ctx) ?=> T]
[48] [error] | ==> commons.Ctx => T <: (commons.Ctx) ?=> T = false
[48] [error] |
[48] [error] | The tests were made under the empty constraint
[48] [error] ----------------------------------------------------------------------------
[48] [error] two errors found
I would be grateful for your help.