scalatest / scalatestplus-scalacheck

ScalaTest + ScalaCheck provides integration support between ScalaTest and ScalaCheck.
Apache License 2.0
57 stars 24 forks source link

ScalaCheckDrivenPropertyChecks migrating to scala 2.13.x #52

Closed BusyByte closed 2 years ago

BusyByte commented 2 years ago

Dep Version

"org.scalatestplus" %% "scalacheck-1-15" % "3.2.10.0"

Overview

Migrating an existing project which is working fine on Scala 2.12 to cross compile/publish/release on Scala 2.13 Introduced the compiler settings sbt-tpolecat for Scala 2.13

//...
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
//...

class EventLoggingTest extends FunSuite with ScalaCheckDrivenPropertyChecks {
//...
test("Logs an event as json") {
    forAll { (evt: Event) =>
      val json = evt.asJson.noSpaces
      EventLogging.event(evt)
      verify(log).info(json)
    }
  }
// ...
}

Problem

I'm getting the following error:

Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method dispatch,
[error] or remove the empty argument list from its definition (Java-defined methods are exempt).
[error] In Scala 3, an unapplied method like this will be eta-expanded into a function.
[error]     forAll { (evt: Event) =>
[error]            ^

I see your test file that is using ScalaCheckDrivenPropertyChecks in this project has been commented out for a while. I've tried adding () at various spots, adding type annotations, etc and nothing I do resolves this. I assume there is a compiler flag I can filter out but don't really want to go down that route if I can fix it.

Question

Is this something you've seen and can recommend how to fix?

BusyByte commented 2 years ago

Update:

So I rewrote this in terms of Prop.forAll and check on org.scalatestplus.scalacheck.Checkers then explicitly passed all the parameters. I think it's having issues with the Arbitrary[a1] We are using Magnolia to generate our Event and was able to move the problem to:

val a: Arbitrary[Event] = gen[Event]

So I think something in the way we are using magnolia or the library itself is the problem as it's a macro:

implicit def gen[T]: Arbitrary[T] = macro Magnolia.gen[T]

So this issue can be closed. I'll have to check out our macro functions to make sure they are ok and if it doesn't look like anything we are doing open this issue in the Magnolia repo.

BusyByte commented 2 years ago

Update: I found the issue in case someone else has the problem, our dispatch function had an extra set of parens on so I changed: def dispatch[T](sealedTrait: SealedTrait[Arbitrary, T])(): Arbitrary[T] to def dispatch[T](sealedTrait: SealedTrait[Arbitrary, T]): Arbitrary[T] and everything works now.