-
Notifications
You must be signed in to change notification settings - Fork 11
Description
In some cases, macros in ReactionMacros.scala/ Macros.scala fail to build correct pattern matching closures.
Testing with scalatest cannot uncover this failure: see https://github.com/Chymyst/joinrun-scala/blob/master/joinrun/src/test/scala/code/chymyst/jc/MacroErrorSpec.scala#L57
This test passes, but writing
val c = m[(Int, (Int, Int))]
go { case c((_, z@(_, _))) => }will not compile. The error is "scalac: Error: Could not find proxy for val x2: Tuple2 in List(value x2, method applyOrElse, ...)"
The error happens after macro expansion. The macro prepares a partial function
{ case (_, z@(_, _)) => } : PartialFunction[Any, Unit]that should detect the pattern match. The code of the partial function is correct. However, the code fails to compile when this partial function is inserted into ReactionInfo.
Removing z@ makes the code compile.
The same thing happens with
val d = m[(Int, Option[Int])]
go { case d((x, z@Some(_))) => }Removing z@ makes the code compile.
A very similar issue is discussed at http://stackoverflow.com/questions/41539029/how-to-use-scala-macros-to-create-new-partial-functions-or-transform-them/41548756
The workarounds discussed there have been tried. Perhaps what's missing is a type annotation on z, or some more c.untypecheck at the right place. Or perhaps it's a missing "owner" on some symbol.