diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..4739710 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Scala Steward: Reformat with scalafmt 3.2.2 +1c7df8c740764927fd3962f34081dc1d0840e43f diff --git a/.scalafmt.conf b/.scalafmt.conf index e780ff0..4d00204 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.2.1 +version = 3.2.2 maxColumn = 120 runner.dialect = scala3 fileOverride { diff --git a/project/plugins.sbt b/project/plugins.sbt index f3eecc8..24ef45a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -8,4 +8,4 @@ addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.1") val sbtSoftwareMillVersion = "2.0.9" addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-common" % sbtSoftwareMillVersion) -addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-publish" % sbtSoftwareMillVersion) \ No newline at end of file +addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-publish" % sbtSoftwareMillVersion) 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 feac364..d949640 100644 --- a/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala +++ b/quicklens/src/main/scala-3/com/softwaremill/quicklens/QuicklensMacros.scala @@ -48,7 +48,9 @@ object QuicklensMacros { def toPathModifyFromFocus[S: Type, A: Type](obj: Expr[S], focus: Expr[S => A])(using Quotes): Expr[PathModify[S, A]] = toPathModify(obj, modifyImpl(obj, Seq(focus))) - private def modifyImpl[S: Type, A: Type](obj: Expr[S], focuses: Seq[Expr[S => A]])(using Quotes): Expr[(A => A) => S] = { + private def modifyImpl[S: Type, A: Type](obj: Expr[S], focuses: Seq[Expr[S => A]])(using + Quotes + ): Expr[(A => A) => S] = { import quotes.reflect.* def unsupportedShapeInfo(tree: Tree) = @@ -69,8 +71,7 @@ object QuicklensMacros { symbols.toPathTree case (PathTree.Node(children), (symbol :: Nil)) => PathTree.Node { - if children.find(_._1 equiv symbol).isEmpty then - children :+ (symbol -> Seq(PathTree.Empty)) + if children.find(_._1 equiv symbol).isEmpty then children :+ (symbol -> Seq(PathTree.Empty)) else children.map { case (sym, trees) if sym equiv symbol => @@ -82,14 +83,14 @@ object QuicklensMacros { this case (PathTree.Node(children), (symbol :: tail)) => PathTree.Node { - if children.find(_._1 equiv symbol).isEmpty then - children :+ (symbol -> Seq(tail.toPathTree)) + if children.find(_._1 equiv symbol).isEmpty then children :+ (symbol -> Seq(tail.toPathTree)) else children.map { case (sym, trees) if sym equiv symbol => - sym -> (trees.init ++ { trees.last match - case PathTree.Empty => Seq(PathTree.Empty, tail.toPathTree) - case node => Seq(node <> tail) + sym -> (trees.init ++ { + trees.last match + case PathTree.Empty => Seq(PathTree.Empty, tail.toPathTree) + case node => Seq(node <> tail) }) case c => c } @@ -101,7 +102,7 @@ object QuicklensMacros { extension (symbols: Seq[PathSymbol]) def toPathTree: PathTree = symbols match - case Nil => PathTree.Empty + case Nil => PathTree.Empty case (symbol :: tail) => PathTree.Node(Seq(symbol -> Seq(tail.toPathTree))) enum PathSymbol: @@ -144,7 +145,7 @@ object QuicklensMacros { def poorMansLUB: TypeRepr = tpe match { case AndType(l, r) if l <:< r => l case AndType(l, r) if r <:< l => r - case _ => tpe + case _ => tpe } def widenAll: TypeRepr = tpe.widen.dealias.poorMansLUB @@ -183,7 +184,7 @@ object QuicklensMacros { def isSum(sym: Symbol): Boolean = { sym.flags.is(Flags.Enum) || - (sym.flags.is(Flags.Sealed) && (sym.flags.is(Flags.Trait) || sym.flags.is(Flags.Abstract))) + (sym.flags.is(Flags.Sealed) && (sym.flags.is(Flags.Trait) || sym.flags.is(Flags.Abstract))) } def caseClassCopy( @@ -221,12 +222,14 @@ object QuicklensMacros { typeParams match { // if the object's type is parametrised, we need to call .copy with the same type parameters case Some(typeParams) => Apply(TypeApply(Select(obj, copy), typeParams.map(Inferred(_))), args) - case _ => Apply(Select(obj, copy), args) + case _ => Apply(Select(obj, copy), args) } } else if isSum(objSymbol) then { obj.tpe.widenAll match { case AndType(_, _) => - report.errorAndAbort(s"Implementation limitation: Cannot modify sealed hierarchies mixed with & types. Try providing a more specific type.") + report.errorAndAbort( + s"Implementation limitation: Cannot modify sealed hierarchies mixed with & types. Try providing a more specific type." + ) case _ => } /* @@ -315,15 +318,16 @@ object QuicklensMacros { } 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)) + 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)) } val pathTree: PathTree = diff --git a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOptimizedTest.scala b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOptimizedTest.scala index 406539f..99da34a 100644 --- a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOptimizedTest.scala +++ b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOptimizedTest.scala @@ -20,7 +20,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft lst .modifyAll( _.head - ).using(_ + 1) + ) + .using(_ + 1) Cons.copyCount should be(1) } @@ -32,7 +33,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft .modifyAll( _.head, _.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Cons.copyCount should be(2) } @@ -45,7 +47,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft _.head, _.tail.each.head, _.tail.each.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Cons.copyCount should be(3) } @@ -57,7 +60,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft .modifyAll( _.tail.each.tail.each.head, _.tail.each.tail.each.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Cons.copyCount should be(4) } @@ -71,8 +75,9 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft _.tail.each.tail, _.tail, _.tail.each.tail - ).using { - case None => None + ) + .using { + case None => None case Some(Cons(head, tail)) => Some(Cons(head + 1, tail)) } @@ -87,9 +92,10 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft _.tail, _.tail.each.tail, _.tail.each.tail, - _.tail, - ).using { - case None => None + _.tail + ) + .using { + case None => None case Some(Cons(head, tail)) => Some(Cons(head + 1, tail)) } @@ -106,9 +112,10 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft _.tail.each.tail, _.tail.each.tail.each.tail.each.tail, _.tail.each.tail, - _.tail, - ).using { - case None => None + _.tail + ) + .using { + case None => None case Some(Cons(head, tail)) => Some(Cons(head + 1, tail)) } @@ -122,7 +129,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft .modifyAll( _.tail.each.head, _.tail.each.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Opt.eachCount should be(2) } @@ -134,7 +142,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft .modifyAll( _.tail.each.head, _.tail.each.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Opt.eachCount should be(2) } @@ -146,7 +155,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft .modifyAll( _.tail.each.tail.each.head, _.tail.each.tail.each.tail.each.head - ).using(_ + 1) + ) + .using(_ + 1) Opt.eachCount should be(3) } @@ -182,7 +192,7 @@ object ModifyAllOptimizedTest { override def get: A = a override def equals(other: Any): Boolean = other match { case Just(a1) => a == a1 - case _ => false + case _ => false } } @@ -190,7 +200,7 @@ object ModifyAllOptimizedTest { def map[A](fa: Opt[A], f: A => A): Opt[A] = Opt.eachCount = Opt.eachCount + 1 fa match { - case Nada => Nada + case Nada => Nada case Just(a) => Just(f(a)) } } @@ -209,4 +219,4 @@ object ModifyAllOptimizedTest { Just(ConsOpt(head, fromList(tail))) } } -} \ No newline at end of file +} diff --git a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOrderTest.scala b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOrderTest.scala index ebc9c92..088ff1e 100644 --- a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOrderTest.scala +++ b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAllOrderTest.scala @@ -15,7 +15,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { .modifyAll( _.tail.each.tail.each, _.tail.each - ).using { + ) + .using { case Cons(head, tail) if head == 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 3 => @@ -35,7 +36,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { .modifyAll( _.tail.each, _.tail.each.tail.each - ).using { + ) + .using { case Cons(head, tail) if head == 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 3 => @@ -56,7 +58,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { _.tail.each.tail.each, _.tail.each, _.tail.each.tail.each - ).using { + ) + .using { case Cons(head, tail) if head >= 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 4 => @@ -77,7 +80,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { _.tail.each.tail.each, _.tail.each.tail.each, _.tail.each - ).using { + ) + .using { case Cons(head, tail) if head >= 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 4 => @@ -98,7 +102,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { _.each.tail.each.tail.each, _.each.tail.each.tail.each, _.each.tail.each - ).using { + ) + .using { case Cons(head, tail) if head >= 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 4 => @@ -119,7 +124,8 @@ class ModifyAllOrderTest extends AnyFlatSpec with Matchers { _.each.tail.each.tail.each, _.each.tail.each, _.each.tail.each.tail.each - ).using { + ) + .using { case Cons(head, tail) if head >= 3 => Cons(head + 1, tail) case Cons(head, Some(Cons(head2, tail))) if head2 == 4 => @@ -141,4 +147,4 @@ object ModifyAllOrderTest { Some(Cons(head, fromList(tail))) } } -} \ No newline at end of file +} diff --git a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAndTypeTest.scala b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAndTypeTest.scala index ff229a3..5d97a9f 100644 --- a/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAndTypeTest.scala +++ b/quicklens/src/test/scala-3/com/softwaremill/quicklens/test/ModifyAndTypeTest.scala @@ -12,7 +12,7 @@ object ModifyAndTypeTest { } case class A1(a: Int) - + sealed trait T case class C(a: Int) extends T with B diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/EnormousModifyAllTest.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/EnormousModifyAllTest.scala index 9ca101d..50d77bc 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/EnormousModifyAllTest.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/EnormousModifyAllTest.scala @@ -27,48 +27,49 @@ class EnormousModifyAllTest extends AnyFlatSpec with Matchers { _.b.a.a.a.a.a, _.c.a.a.a.a.a, _.d.a.a.a.a.a - ).using(_ + 1) + ) + .using(_ + 1) res should be(c1e) } } object EnormousModifyAllTest { case class C1( - a: C2, - b: C2, - c: C2, - d: C2 + a: C2, + b: C2, + c: C2, + d: C2 ) case class C2( - a: C3, - b: C3, - c: C3, - d: C3 + a: C3, + b: C3, + c: C3, + d: C3 ) case class C3( - a: C4, - b: C4, - c: C4, - d: C4 + a: C4, + b: C4, + c: C4, + d: C4 ) case class C4( - a: C5, - b: C5, - c: C5, - d: C5 + a: C5, + b: C5, + c: C5, + d: C5 ) case class C5( - a: C6, - b: C6, - c: C6, - d: C6 + a: C6, + b: C6, + c: C6, + d: C6 ) case class C6( - a: Int + a: Int ) } diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/HugeModifyTest.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/HugeModifyTest.scala index 814b24e..5f86698 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/HugeModifyTest.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/HugeModifyTest.scala @@ -24,41 +24,42 @@ class HugeModifyTest extends AnyFlatSpec with Matchers { _.a.a.a.a.a, _.b.a.a.a.a, _.c.a.a.a.a - ).using(_ + 1) + ) + .using(_ + 1) res should be(c1e) } } object HugeModifyTestData { case class C1( - a: C2, - b: C2, - c: C2, - d: C2 + a: C2, + b: C2, + c: C2, + d: C2 ) case class C2( - a: C3, - b: C3, - c: C3, - d: C3 + a: C3, + b: C3, + c: C3, + d: C3 ) case class C3( - a: C4, - b: C4, - c: C4, - d: C4 + a: C4, + b: C4, + c: C4, + d: C4 ) case class C4( - a: C5, - b: C5, - c: C5, - d: C5 + a: C5, + b: C5, + c: C5, + d: C5 ) case class C5( - a: Int + a: Int ) } diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyAllTest.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyAllTest.scala index 3bfc711..ca7edcb 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyAllTest.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/RepeatedModifyAllTest.scala @@ -33,7 +33,8 @@ class RepeatedModifyAllTest extends AnyFlatSpec with Matchers { _.a.a.a.a.a.a, _.a.a.a.a.a.a, _.a.a.a.a.a.a - ).setTo(2) + ) + .setTo(2) res should be(c1e) } @@ -64,33 +65,34 @@ class RepeatedModifyAllTest extends AnyFlatSpec with Matchers { _.a.a.a.a.a.a, _.a.a.a.a.a.a, _.a.a.a.a.a.a - ).using(_ + 1) + ) + .using(_ + 1) res should be(c1e) } } object RepeatedModifyAllTest { case class C1( - a: C2 + a: C2 ) case class C2( - a: C3 + a: C3 ) case class C3( - a: C4 + a: C4 ) case class C4( - a: C5 + a: C5 ) case class C5( - a: C6 + a: C6 ) case class C6( - a: Int + a: Int ) } diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/SealedTest.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/SealedTest.scala index 63092fc..e0eb706 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/SealedTest.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/SealedTest.scala @@ -4,9 +4,8 @@ import com.softwaremill.quicklens.TestData.duplicate import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers -/** - * This test data is in the same file as the test to ensure correct compilation order. - * See https://issues.scala-lang.org/browse/SI-7046. +/** This test data is in the same file as the test to ensure correct compilation order. See + * https://issues.scala-lang.org/browse/SI-7046. */ object SealedTestData { case class G(p1: Option[P1]) diff --git a/quicklens/src/test/scala/com/softwaremill/quicklens/TestData.scala b/quicklens/src/test/scala/com/softwaremill/quicklens/TestData.scala index 73cfd97..7e1bc15 100644 --- a/quicklens/src/test/scala/com/softwaremill/quicklens/TestData.scala +++ b/quicklens/src/test/scala/com/softwaremill/quicklens/TestData.scala @@ -63,7 +63,6 @@ object TestData { val ll1at2eachdup = List(List(A5("d1"), A5("d2")), List(A5("d3"), A5("d4"), A5("d5")), List(A5("d6d6"), A5("d7d7"))) val ll1eachat1dup = List(List(A5("d1"), A5("d2d2")), List(A5("d3"), A5("d4d4"), A5("d5")), List(A5("d6"), A5("d7d7"))) - val s1: Seq[A3] = l1 val ss1: Seq[Seq[A5]] = ll1