diff --git a/build.sbt b/build.sbt index 09a25dfe1..69b11a8a1 100644 --- a/build.sbt +++ b/build.sbt @@ -49,6 +49,16 @@ lazy val buildSettings = Seq( "-deprecation" ) ++ { if (tlIsScala3.value) Seq() else Seq("-Xfatal-warnings") }, // Scala 3 doesn't support -Wconf Compile / console / scalacOptions -= "-Ywarn-unused:imports", + scalacOptions ++= { + scalaBinaryVersion.value match { + case "2.12" => + Seq("-Xsource:3") + case "2.13" => + Seq("-Xsource:3-cross") + case _ => + Nil + } + }, scalacOptions ++= { if (tlIsScala3.value) Seq( diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/KeywordParserBase.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/KeywordParserBase.scala index c3bd844e5..10082667d 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/KeywordParserBase.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/KeywordParserBase.scala @@ -22,7 +22,7 @@ private[focus] trait KeywordParserBase extends ParserBase { Some( Name(keyword), FromType(code.tpe.widen), - TypeArgs(inferredTypeArgs.map(_.tpe): _*), + TypeArgs(inferredTypeArgs.map(_.tpe)*), ValueArgs(), RemainingCode(code) ) @@ -32,8 +32,8 @@ private[focus] trait KeywordParserBase extends ParserBase { Some( Name(keyword), FromType(code.tpe.widen), - TypeArgs(inferredTypeArgs.map(_.tpe): _*), - ValueArgs(valueArgs: _*), + TypeArgs(inferredTypeArgs.map(_.tpe)*), + ValueArgs(valueArgs*), RemainingCode(code) ) @@ -42,7 +42,7 @@ private[focus] trait KeywordParserBase extends ParserBase { Some( Name(keyword), FromType(code.tpe.widen), - TypeArgs(directTypeArgs.map(_.tpe): _*), + TypeArgs(directTypeArgs.map(_.tpe)*), ValueArgs(), RemainingCode(code) ) @@ -53,7 +53,7 @@ private[focus] trait KeywordParserBase extends ParserBase { Some( Name(keyword), FromType(code.tpe.widen), - TypeArgs(allTypeArgs.map(_.tpe): _*), + TypeArgs(allTypeArgs.map(_.tpe)*), ValueArgs(), RemainingCode(code) ) diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/as/AsParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/as/AsParser.scala index 629f1ae7c..2cc064722 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/as/AsParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/as/AsParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait AsParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordAs extends FocusParser { diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/at/AtParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/at/AtParser.scala index dc8f700a2..27b2d5a46 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/at/AtParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/at/AtParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait AtParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordAt extends FocusParser { diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/each/EachParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/each/EachParser.scala index 4ac190476..64634b82f 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/each/EachParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/each/EachParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait EachParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordEach extends FocusParser { diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/index/IndexParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/index/IndexParser.scala index 57982b703..062174f0e 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/index/IndexParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/index/IndexParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait IndexParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordIndex extends FocusParser { diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/selectfield/SelectFieldParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/selectfield/SelectFieldParser.scala index 84d3bcf99..185c9ceaa 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/selectfield/SelectFieldParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/selectfield/SelectFieldParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.SelectParserBase private[focus] trait SelectFieldParser { - this: FocusBase with SelectParserBase => + this: FocusBase & SelectParserBase => import this.macroContext.reflect._ diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/selectonlyfield/SelectOnlyFieldParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/selectonlyfield/SelectOnlyFieldParser.scala index 9ff1de75f..d2aa8e07d 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/selectonlyfield/SelectOnlyFieldParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/selectonlyfield/SelectOnlyFieldParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.SelectParserBase private[focus] trait SelectOnlyFieldParser { - this: FocusBase with SelectParserBase => + this: FocusBase & SelectParserBase => import this.macroContext.reflect._ diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/some/SomeParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/some/SomeParser.scala index 282dc24e3..66b0777cb 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/some/SomeParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/some/SomeParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait SomeParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordSome extends FocusParser { diff --git a/core/shared/src/main/scala-3/monocle/internal/focus/features/withdefault/WithDefaultParser.scala b/core/shared/src/main/scala-3/monocle/internal/focus/features/withdefault/WithDefaultParser.scala index f7c53b0b9..0a48520b9 100644 --- a/core/shared/src/main/scala-3/monocle/internal/focus/features/withdefault/WithDefaultParser.scala +++ b/core/shared/src/main/scala-3/monocle/internal/focus/features/withdefault/WithDefaultParser.scala @@ -4,7 +4,7 @@ import monocle.internal.focus.FocusBase import monocle.internal.focus.features.KeywordParserBase private[focus] trait WithDefaultParser { - this: FocusBase with KeywordParserBase => + this: FocusBase & KeywordParserBase => object KeywordWithDefault extends FocusParser { diff --git a/core/shared/src/main/scala/monocle/Fold.scala b/core/shared/src/main/scala/monocle/Fold.scala index 4f9c4f7b4..bc7e49882 100644 --- a/core/shared/src/main/scala/monocle/Fold.scala +++ b/core/shared/src/main/scala/monocle/Fold.scala @@ -35,23 +35,23 @@ trait Fold[S, A] extends Serializable { self => /** find the first target matching the predicate */ def find(p: A => Boolean): S => Option[A] = - foldMap(a => Some(a).filter(p))(_)(Monoids.firstOption) + foldMap(a => Some(a).filter(p))(_)(using Monoids.firstOption) /** get the first target */ def headOption(s: S): Option[A] = - foldMap(Option(_))(s)(Monoids.firstOption) + foldMap(Option(_))(s)(using Monoids.firstOption) /** get the last target */ def lastOption(s: S): Option[A] = - foldMap(Option(_))(s)(Monoids.lastOption) + foldMap(Option(_))(s)(using Monoids.lastOption) /** check if at least one target satisfies the predicate */ def exist(p: A => Boolean): S => Boolean = - foldMap(p(_))(_)(Monoids.any) + foldMap(p(_))(_)(using Monoids.any) /** check if all targets satisfy the predicate */ def all(p: A => Boolean): S => Boolean = - foldMap(p(_))(_)(Monoids.all) + foldMap(p(_))(_)(using Monoids.all) /** calculate the number of targets */ def length(s: S): Int = @@ -59,7 +59,7 @@ trait Fold[S, A] extends Serializable { self => /** check if there is no target */ def isEmpty(s: S): Boolean = - foldMap(_ => false)(s)(Monoids.all) + foldMap(_ => false)(s)(using Monoids.all) /** check if there is at least one target */ def nonEmpty(s: S): Boolean = diff --git a/core/shared/src/main/scala/monocle/Traversal.scala b/core/shared/src/main/scala/monocle/Traversal.scala index a3575fda2..a3e2693f9 100644 --- a/core/shared/src/main/scala/monocle/Traversal.scala +++ b/core/shared/src/main/scala/monocle/Traversal.scala @@ -50,7 +50,7 @@ trait PTraversal[S, T, A, B] extends PSetter[S, T, A, B] with Fold[S, A] { self */ def parModifyF[F[_]](f: A => F[B])(s: S)(implicit F: Parallel[F]): F[T] = F.sequential( - modifyA(a => F.parallel(f(a)))(s)(F.applicative) + modifyA(a => F.parallel(f(a)))(s)(using F.applicative) ) override def some[A1, B1](implicit ev1: A =:= Option[A1], ev2: B =:= Option[B1]): PTraversal[S, T, A1, B1] = diff --git a/core/shared/src/main/scala/monocle/function/FilterIndex.scala b/core/shared/src/main/scala/monocle/function/FilterIndex.scala index e67c66911..aaeba449d 100644 --- a/core/shared/src/main/scala/monocle/function/FilterIndex.scala +++ b/core/shared/src/main/scala/monocle/function/FilterIndex.scala @@ -91,7 +91,7 @@ object FilterIndex extends FilterIndexFunctions { .traverse { case (k, v) => (if (predicate(k)) f(v) else v.pure[F]).tupleLeft(k) } - .map(kvs => SortedMap(kvs: _*)(ok.toOrdering)) + .map(kvs => SortedMap(kvs *)(ok.toOrdering)) } } diff --git a/example/src/test/scala-2/monocle/HttpRequestExample.scala b/example/src/test/scala-2/monocle/HttpRequestExample.scala index 5ccfc054e..b638e43ba 100644 --- a/example/src/test/scala-2/monocle/HttpRequestExample.scala +++ b/example/src/test/scala-2/monocle/HttpRequestExample.scala @@ -60,7 +60,7 @@ class HttpRequestExample extends MonocleSuite { test("headers with filterIndex") { val r = headers - .filterIndex { h: String => h.contains("timeout") } + .filterIndex((h: String) => h.contains("timeout")) .andThen(stringToInt) .modify(_ * 2)(r1) diff --git a/example/src/test/scala-2/monocle/JsonExample.scala b/example/src/test/scala-2/monocle/JsonExample.scala index 8a8219eef..0e30d73f3 100644 --- a/example/src/test/scala-2/monocle/JsonExample.scala +++ b/example/src/test/scala-2/monocle/JsonExample.scala @@ -218,8 +218,8 @@ class JsonExample extends MonocleSuite { def modifyA[F[_]: Applicative](f: Json => F[Json])(a: Json): F[Json] = a match { case j @ (JsString(_) | JsNumber(_)) => Applicative[F].pure(j) - case JsArray(l) => l.traverse(f).map(JsArray) - case JsObject(m) => Traverse[Map[String, *]].traverse(m)(f).map(JsObject) + case JsArray(l) => l.traverse(f).map(JsArray.apply) + case JsObject(m) => Traverse[Map[String, *]].traverse(m)(f).map(JsObject.apply) } } } diff --git a/example/src/test/scala-2/monocle/function/FilterIndexExample.scala b/example/src/test/scala-2/monocle/function/FilterIndexExample.scala index b14064089..497614fbe 100644 --- a/example/src/test/scala-2/monocle/function/FilterIndexExample.scala +++ b/example/src/test/scala-2/monocle/function/FilterIndexExample.scala @@ -9,7 +9,7 @@ class FilterIndexExample extends MonocleSuite { assertEquals( SortedMap("One" -> 1, "Two" -> 2) .focus() - .filterIndex { k: String => + .filterIndex { (k: String) => k.toLowerCase.contains("o") } .getAll, @@ -21,7 +21,7 @@ class FilterIndexExample extends MonocleSuite { assertEquals( SortedMap("One" -> 1, "Two" -> 2) .focus() - .filterIndex { k: String => + .filterIndex { (k: String) => k.startsWith("T") } .replace(3), @@ -35,11 +35,11 @@ class FilterIndexExample extends MonocleSuite { test( "filterIndexes creates Traversal from a List, IList, Vector or Stream to all values where the index matches the predicate" ) { - assertEquals(List(1, 3, 5, 7).focus().filterIndex { i: Int => i % 2 == 0 }.getAll, List(1, 5)) + assertEquals(List(1, 3, 5, 7).focus().filterIndex((i: Int) => i % 2 == 0).getAll, List(1, 5)) - assertEquals(List(1, 3, 5, 7).focus().filterIndex { i: Int => i >= 2 }.modify(_ + 2), List(1, 3, 7, 9)) + assertEquals(List(1, 3, 5, 7).focus().filterIndex((i: Int) => i >= 2).modify(_ + 2), List(1, 3, 7, 9)) assertEquals( - Vector(1, 3, 5, 7).focus().filterIndex { i: Int => i >= 2 }.modify(_ + 2), + Vector(1, 3, 5, 7).focus().filterIndex((i: Int) => i >= 2).modify(_ + 2), Vector(1, 3, 7, 9) ) } diff --git a/macro/src/test/scala/monocle/macros/GenPrismSpec.scala b/macro/src/test/scala/monocle/macros/GenPrismSpec.scala index 35a6e7a61..779be5716 100644 --- a/macro/src/test/scala/monocle/macros/GenPrismSpec.scala +++ b/macro/src/test/scala/monocle/macros/GenPrismSpec.scala @@ -11,8 +11,8 @@ class GenPrismSpec extends DisciplineSuite { case class I(i: Int) extends IntOrString case class S(s: String) extends IntOrString - implicit val iArb: Arbitrary[I] = Arbitrary(arbitrary[Int].map(I)) - implicit val sArb: Arbitrary[S] = Arbitrary(arbitrary[String].map(S)) + implicit val iArb: Arbitrary[I] = Arbitrary(arbitrary[Int].map(I.apply)) + implicit val sArb: Arbitrary[S] = Arbitrary(arbitrary[String].map(S.apply)) implicit val intOrStringArb: Arbitrary[IntOrString] = Arbitrary(Gen.oneOf(iArb.arbitrary, sArb.arbitrary))