Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Update to Scala 2.13.13 and avoid unused parameter value warning in macro #56

Closed
wants to merge 7 commits into from
Closed
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: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
fail-fast: false
matrix:
java: ['8', '11', '17']
scala: ['2.12.17', '2.13.10', '3.3.1']
scala: ['2.12.17', '2.13.13', '3.3.1']
platform: ['JVM', 'JS', 'Native']
steps:
- name: Checkout current branch
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ lazy val mock = crossProject(JSPlatform, JVMPlatform, NativePlatform)
if (scalaVersion.value == Scala3)
Seq.empty
else
Seq("-P:silencer:globalFilters=[zio.stacktracer.TracingImplicits.disableAutoTrace]")
Seq("-Wconf:cat=unused&origin=zio.stacktracer.TracingImplicits.disableAutoTrace:s")
}
)
.enablePlugins(BuildInfoPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import zio.test.{Spec, ZIOSpecDefault, assertZIO}
import zio.{Clock, Console, Random, ZIO}

import java.io.IOException
import scala.annotation.nowarn

@nowarn("msg=ZLAYER WARNING")
object MockExampleSpec extends ZIOSpecDefault {

def spec: Spec[Any, IOException] = suite("suite with mocks")(
Expand Down Expand Up @@ -44,12 +46,12 @@ object MockExampleSpec extends ZIOSpecDefault {
branchingProgram(p1) <*> branchingProgram(p2)

val clockLayer = (MockClock.NanoTime(value(42L)) andThen MockClock.NanoTime(value(42L))).toLayer
val noCallToConsole = composedBranchingProgram(false, false)
val noCallToConsole = composedBranchingProgram(p1 = false, p2 = false)
.provide(MockConsole.empty ++ clockLayer)

val consoleLayer =
(MockConsole.ReadLine(value("foo")) andThen MockConsole.ReadLine(value("foo"))).toLayer
val noCallToClock = composedBranchingProgram(true, true)
val noCallToClock = composedBranchingProgram(p1 = true, p2 = true)
.provide(MockClock.empty ++ consoleLayer)

assertZIO(noCallToConsole)(equalTo((42L, 42L))) *> assertZIO(noCallToClock)(equalTo(("foo", "foo")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ object MockReporterSpec extends ZIOSpecDefault {
unsatisfiedExpectationSuite
) @@ MockReporter()

executeSpec(testCase, true).as(assertTrue(true))
executeSpec(testCase, showSpecOutput = true).as(assertTrue(true))
}

def verifyRendering(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package zio.mock.module

import com.github.ghik.silencer.silent
import zio.{EnvironmentTag, URIO, ZIO}

import scala.annotation.nowarn

/** Example of impure module used for testing ZIO Mock framework.
*/
trait ImpureModule {
Expand All @@ -11,7 +12,7 @@ trait ImpureModule {
def singleParam(a: Int): String
def manyParams(a: Int, b: String, c: Long): String
def manyParamLists(a: Int)(b: String)(c: Long): String
@silent("side-effecting nullary methods")
@nowarn("msg=side-effecting nullary methods")
def command: Unit
def parameterizedCommand(a: Int): Unit
def overloaded(n: Int): String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package zio.mock.module

import com.github.ghik.silencer.silent
import zio.mock.{Mock, Proxy}
import zio.{EnvironmentTag, URLayer, Unsafe, ZIO, ZLayer}

import scala.annotation.nowarn

/** Example module used for testing ZIO Mock framework.
*/
object ImpureModuleMock extends Mock[ImpureModule] {
Expand Down Expand Up @@ -64,7 +65,7 @@ object ImpureModuleMock extends Mock[ImpureModule] {
rts.unsafe.run(proxy(ManyParamLists, a, b, c)).getOrThrow()
}

@silent("side-effecting nullary methods")
@nowarn("msg=side-effecting nullary methods")
def command: Unit = Unsafe.unsafe { implicit u =>
rts.unsafe.run(proxy(Command)).getOrThrow()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package zio.mock.module

import com.github.ghik.silencer.silent
import zio.{IO, EnvironmentTag, URIO, ZIO}
import zio.{EnvironmentTag, IO, URIO, ZIO}

import scala.annotation.nowarn
import scala.reflect.ClassTag

/** Example module used for testing ZIO Mock framework.
Expand Down Expand Up @@ -58,7 +58,7 @@ trait PureModule {
): IO[String, String]
}

@silent("never used")
@nowarn("msg=never used")
object PureModule {

// Workaround for izumi.reflect.EnvironmentTag any-kindness (probably?) causing `Any` to be inferred on dotty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package zio.mock.module

import com.github.ghik.silencer.silent
import zio.mock.{Mock, Proxy}
import zio.{EnvironmentTag, IO, UIO, URLayer, ZIO, ZLayer}

import scala.annotation.nowarn

/** Example pure module used for testing ZIO Mock framework.
*/
object PureModuleMock extends Mock[PureModule] {
Expand Down Expand Up @@ -37,7 +38,7 @@ object PureModuleMock extends Mock[PureModule] {

object MaxParams extends Effect[T22[Int], String, String]

@silent("is never used")
@nowarn("msg=is never used")
val compose: URLayer[Proxy, PureModule] =
ZLayer.fromZIO(
ZIO
Expand Down
8 changes: 4 additions & 4 deletions mock/shared/src/main/scala-2/zio/mock/MockableMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package zio.mock

import com.github.ghik.silencer.silent
import zio.test.TestVersion
import scala.annotation.nowarn

import scala.reflect.macros.whitebox.Context

/** Generates method tags for a service into annotated object.
*/
private[mock] object MockableMacro {

@silent
@nowarn
def impl(c: Context)(annottees: c.Tree*): c.Expr[c.Tree] = {
import c.universe._

Expand Down Expand Up @@ -330,14 +329,15 @@ private[mock] object MockableMacro {
_root_.zio.ZLayer.fromZIO(
_root_.zio.ZIO.service[_root_.zio.mock.Proxy].flatMap { proxy =>
withRuntime[_root_.zio.mock.Proxy, $service] { rts =>
rts.toString() // workaround to avoid 'parameter rts in anonymous function is never used' warnings
class $serviceClassName extends $service {
..$mocks
}
_root_.zio.ZIO.succeed { new $serviceClassName }
}
}
)

..$body
}
"""
Expand Down
2 changes: 2 additions & 0 deletions mock/shared/src/main/scala/zio/mock/Capability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import zio.test.Assertion
import zio.{=!=, EnvironmentTag, IO, LightTypeTag, ZIO, taggedIsSubtype, taggedTagType}

import java.util.UUID
import scala.annotation.nowarn

/** A `Capability[R, I, E, A]` represents a capability of environment `R` that takes an input `I` and returns an effect
* that may fail with an error `E` or produce a single `A`.
Expand Down Expand Up @@ -84,6 +85,7 @@ object Capability {

sealed abstract class Unknown

@nowarn("msg=evidence parameter.*is never used")
protected[mock] abstract class Poly[R: EnvironmentTag, I, E, A] extends Base[R]

object Poly {
Expand Down
2 changes: 1 addition & 1 deletion mock/shared/src/main/scala/zio/mock/Expectation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package zio.mock

import zio.mock.Expectation.{And, Chain, Exactly, Or, Repeated}
import zio.mock.Result.{Fail, Succeed}
import zio.mock.internal.{ExpectationState, MockException, MockState, ProxyFactory}
import zio.mock.internal.{ExpectationState, MockState, ProxyFactory}
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.test.Assertion
import zio.{EnvironmentTag, IO, Trace, ULayer, URLayer, ZIO, ZLayer}
Expand Down
3 changes: 3 additions & 0 deletions mock/shared/src/main/scala/zio/mock/Mock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import zio.stream.{ZSink, ZStream}
import zio.test.TestPlatform
import zio.{EnvironmentTag, Runtime, RuntimeFlag, RuntimeFlags, Trace, UIO, ULayer, URLayer, ZIO}

import scala.annotation.nowarn

/** A `Mock[R]` represents a mockable environment `R`.
*/
@nowarn("msg=evidence parameter.*is never used")
abstract class Mock[R: EnvironmentTag] { self =>

protected[mock] val compose: URLayer[Proxy, R]
Expand Down
3 changes: 1 addition & 2 deletions mock/shared/src/main/scala/zio/mock/MockReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ object MockReporter {
}))
}

private def renderCall(call: Expectation.Call[_, _, _, _], additionalDetails: Option[String] = None): String = {
private def renderCall(call: Expectation.Call[_, _, _, _], additionalDetails: Option[String]): String = {
val capability = call.capability
val assertion = call.assertion
val mock = call.mock
val state = call.state
val invocations = call.invocations
val details = additionalDetails.getOrElse(
s"However, it was ${bold(red("never"))} called and is considered ${renderState(state)}."
)
Expand Down
12 changes: 0 additions & 12 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object BuildHelper {
val Scala213: String = versions("2.13")
val Scala3: String = versions("3.3")

val SilencerVersion = "1.7.12"
val SjsJavaTimeVersion = "2.3.0"

private val stdOptions = Seq(
Expand Down Expand Up @@ -212,17 +211,6 @@ object BuildHelper {
crossScalaVersions := Seq(Scala212, Scala213, Scala3),
ThisBuild / scalaVersion := Scala213,
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value),
libraryDependencies ++= {
if (scalaVersion.value == Scala3)
Seq(
"com.github.ghik" % s"silencer-lib_$Scala213" % SilencerVersion % Provided
)
else
Seq(
"com.github.ghik" % "silencer-lib" % SilencerVersion % Provided cross CrossVersion.full,
compilerPlugin("com.github.ghik" % "silencer-plugin" % SilencerVersion cross CrossVersion.full)
)
},
semanticdbEnabled := scalaVersion.value != Scala3, // enable SemanticDB
semanticdbOptions += "-P:semanticdb:synthetics:on",
semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.12")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
addSbtPlugin("com.github.sbt" % "sbt-unidoc" % "0.5.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
Expand All @@ -12,7 +12,7 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject"
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("pl.project13.scala" % "sbt-jcstress" % "0.2.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.1")
Expand Down
Loading