Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, missed that - fixing in #182

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

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 }

Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

}