diff --git a/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala b/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala index 7fbd08c..904922a 100644 --- a/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala +++ b/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala @@ -326,19 +326,24 @@ object QuicklensMacros { accumulateToCopy(owner, mod, objTerm, children) } - val focusesTrees: Seq[Tree] = focuses.map(_.asTerm) - val paths: Seq[Seq[PathSymbol]] = focusesTrees.zip(focuses).map { (tree, focus) => - tree match - /** Single inlined path */ - case Inlined(_, _, Block(List(DefDef(_, _, _, Some(p))), _)) => - toPath(p, focus) - /** One of paths from modifyAll */ - case Block(List(DefDef(_, _, _, Some(p))), _) => - toPath(p, focus) - case _ => - report.errorAndAbort(unsupportedShapeInfo(tree)) + def extractFocus(tree: Tree): Tree = tree match { + /** Single inlined path */ + case Inlined(_, _, p) => + extractFocus(p) + /** One of paths from modifyAll */ + case Block(List(DefDef(_, _, _, Some(p))), _) => + p + case _ => + println(tree) + report.errorAndAbort(unsupportedShapeInfo(tree)) } + val focusesTrees: Seq[Tree] = focuses.map(_.asTerm) + val paths: Seq[Seq[PathSymbol]] = + focusesTrees.zip(focuses).map { (tree, focus) => + toPath(extractFocus(tree), focus) + } + val pathTree: PathTree = paths.foldLeft(PathTree.empty) { (tree, path) => tree <> path } diff --git a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/CustomModifyProxyTest.scala b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/CustomModifyProxyTest.scala new file mode 100644 index 0000000..4ecf975 --- /dev/null +++ b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/CustomModifyProxyTest.scala @@ -0,0 +1,22 @@ +package com.softwaremill.quicklens.test + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers +import com.softwaremill.quicklens.* + +class CustomModifyProxyTest extends AnyFlatSpec with Matchers { + + it should "correctly modify a class using a custom modify proxy method" in { + case class State(foo: Int) + + inline def set[A](state: State, inline path: State => A, value: A): State = { + modify(state)(path).setTo(value) + } + + val state = State(100) + val res = set(state, _.foo, 200) + val expected = State(200) + res.shouldBe(expected) + } + +}