Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.2.2 #107

Merged
merged 3 commits into from
Sep 6, 2022
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.2.2
1c7df8c740764927fd3962f34081dc1d0840e43f
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.2.1
version = 3.2.2
maxColumn = 120
runner.dialect = scala3
fileOverride {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-publish" % sbtSoftwareMillVersion)
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -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 =>
Expand All @@ -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
}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 _ =>
}
/*
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ModifyAllOptimizedTest extends AnyFlatSpec with Matchers with BeforeAndAft
lst
.modifyAll(
_.head
).using(_ + 1)
)
.using(_ + 1)

Cons.copyCount should be(1)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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))
}

Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -182,15 +192,15 @@ object ModifyAllOptimizedTest {
override def get: A = a
override def equals(other: Any): Boolean = other match {
case Just(a1) => a == a1
case _ => false
case _ => false
}
}

given QuicklensFunctor[Opt] with {
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))
}
}
Expand All @@ -209,4 +219,4 @@ object ModifyAllOptimizedTest {
Just(ConsOpt(head, fromList(tail)))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -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 =>
Expand All @@ -141,4 +147,4 @@ object ModifyAllOrderTest {
Some(Cons(head, fromList(tail)))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object ModifyAndTypeTest {
}

case class A1(a: Int)

sealed trait T
case class C(a: Int) extends T with B

Expand Down
Loading