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

scala.NotImplementedError: an implementation is missing at AsmTestRunner$.matchFingerprints$$anonfun$1 #1158

Closed
armanbilge opened this issue Jul 6, 2022 · 6 comments · Fixed by #1190

Comments

@armanbilge
Copy link
Contributor

armanbilge commented Jul 6, 2022

Version(s)

0.1.9

Describe the bug

scala.NotImplementedError: an implementation is missing
  scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
  scala.build.testrunner.AsmTestRunner$.matchFingerprints$$anonfun$1(AsmTestRunner.scala:92)
  scala.collection.IterableOnceOps.find(IterableOnce.scala:622)
  scala.collection.IterableOnceOps.find$(IterableOnce.scala:618)
  scala.collection.AbstractIterable.find(Iterable.scala:926)
  scala.build.testrunner.AsmTestRunner$.matchFingerprints(AsmTestRunner.scala:93)
 ...

To Reproduce

scala-cli test bug.scala
//> using scala "2.13.8"
//> using platform "native"
//> using lib "org.typelevel::cats-kernel-laws::2.8.0"
//> using lib "eu.timepit::refined::0.10.1"

import cats.kernel._
import cats.kernel.laws.discipline._
import eu.timepit.refined._
import eu.timepit.refined.api._
import eu.timepit.refined.types.numeric._
import eu.timepit.refined.numeric.Positive

import org.scalacheck._

class BugSpec extends Properties("bugged") {

  implicit val posByteCommutativeSemigroup: CommutativeSemigroup[PosByte] =
    getPosIntegralCommutativeSemigroup[Byte]

  private def getPosIntegralCommutativeSemigroup[A: CommutativeSemigroup: NonNegShift](implicit
      integral: Integral[A],
      v: Validate[A, Positive]
  ): CommutativeSemigroup[A Refined Positive] =
    CommutativeSemigroup.instance { (x, y) =>
      val combined: A = Semigroup[A].combine(x.value, y.value)

      refineV[Positive](combined).getOrElse {
        val result: A =
          CommutativeSemigroup[A].combine(NonNegShift[A].shift(combined), integral.one)
        refineV[Positive].unsafeFrom(result)
      }
    }

  implicit def eq: Eq[PosByte] = Eq.by(_.value)

  implicit def arb: Arbitrary[PosByte] =
    Arbitrary(Gen.choose(0.toByte, Byte.MaxValue).map(refineV[Positive](_).toOption.get))

  property("propped") = CommutativeSemigroupTests[PosByte].commutativeSemigroup.props(0)._2

}


/**
 * Typeclass to shift Negative values to Non Negative values.
 */
trait NonNegShift[T] extends Serializable {
  def shift(t: T): T
}

object NonNegShift {
  def apply[T](implicit ev: NonNegShift[T]): NonNegShift[T] = ev

  def instance[T](function: T => T): NonNegShift[T] =
    new NonNegShift[T] {
      def shift(t: T): T = function(t)
    }

  // Instances
  implicit val byteNonNegShift: NonNegShift[Byte] = instance(t => (t & Byte.MaxValue).toByte)
  implicit val shortNonNegShift: NonNegShift[Short] = instance(t => (t & Short.MaxValue).toShort)
  implicit val intNonNegShift: NonNegShift[Int] = instance(t => t & Int.MaxValue)
  implicit val longNonNegShift: NonNegShift[Long] = instance(t => t & Long.MaxValue)
}
@lwronski lwronski self-assigned this Jul 7, 2022
@lwronski
Copy link
Contributor

Hi @armanbilge,

thanks for reporting, when I'm trying to run this test using sbt I see the following error:

[info] Starting process '/Users/lwronski/projects/scala-native-seed-project/target/scala-2.13/scala-native-seed-project-test-out' on port '50305'.
failing seed for bugged.propped is z2Y9G0HGOUzxJD_rK4UR4MHcUVccYqaX0vQdiCx5y1J=native-seed-project / Test / nativeLink 14s
[info] ! bugged.propped: Exception raised on property evaluation.
[info] > ARG_0: 116
[info] > ARG_1: 85
[info] > Exception: java.lang.ClassCastException: java.lang.Byte cannot be cast to eu.timepit.refined.api.Refined
[info] Failed: Total 1, Failed 0, Errors 1, Passed 0
[error] Error during tests:
[error]         BugSpec
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 20 s, completed Jul 15, 2022, 10:12:38 A

Are you able to run this test using sbt? If yes, could you attach to issue the configuration of build.sbt?

@armanbilge
Copy link
Contributor Author

@lwronski thanks for looking at this. That error is actually the correct result for running this test. I was using scala-cli to minimize scala-native/scala-native#2712 and I encountered the error reported here along the way.

@lwronski lwronski linked a pull request Jul 18, 2022 that will close this issue
@lwronski
Copy link
Contributor

It's weird, but if you add ScalaCheck dependency //> using lib "org.scalacheck::scalacheck::1.16.0 it's works:

//> using scala "2.13.8"
//> using platform "native"
//> using lib "org.typelevel::cats-kernel-laws::2.8.0"
//> using lib "eu.timepit::refined::0.10.1"
//> using lib "org.scalacheck::scalacheck::1.16.0"

import cats.kernel._
import cats.kernel.laws.discipline._
import eu.timepit.refined._
import eu.timepit.refined.api._
import eu.timepit.refined.types.numeric._
import eu.timepit.refined.numeric.Positive

import org.scalacheck._

class BugSpec extends Properties("bugged") {

  implicit val posByteCommutativeSemigroup: CommutativeSemigroup[PosByte] =
    getPosIntegralCommutativeSemigroup[Byte]

  private def getPosIntegralCommutativeSemigroup[A: CommutativeSemigroup: NonNegShift](implicit
      integral: Integral[A],
      v: Validate[A, Positive]
  ): CommutativeSemigroup[A Refined Positive] =
    CommutativeSemigroup.instance { (x, y) =>
      val combined: A = Semigroup[A].combine(x.value, y.value)

      refineV[Positive](combined).getOrElse {
        val result: A =
          CommutativeSemigroup[A].combine(NonNegShift[A].shift(combined), integral.one)
        refineV[Positive].unsafeFrom(result)
      }
    }

  implicit def eq: Eq[PosByte] = Eq.by(_.value)

  implicit def arb: Arbitrary[PosByte] =
    Arbitrary(Gen.choose(0.toByte, Byte.MaxValue).map(refineV[Positive](_).toOption.get))

  property("propped") = CommutativeSemigroupTests[PosByte].commutativeSemigroup.props(0)._2

}


/**
 * Typeclass to shift Negative values to Non Negative values.
 */
trait NonNegShift[T] extends Serializable {
  def shift(t: T): T
}

object NonNegShift {
  def apply[T](implicit ev: NonNegShift[T]): NonNegShift[T] = ev

  def instance[T](function: T => T): NonNegShift[T] =
    new NonNegShift[T] {
      def shift(t: T): T = function(t)
    }

  // Instances
  implicit val byteNonNegShift: NonNegShift[Byte] = instance(t => (t & Byte.MaxValue).toByte)
  implicit val shortNonNegShift: NonNegShift[Short] = instance(t => (t & Short.MaxValue).toShort)
  implicit val intNonNegShift: NonNegShift[Int] = instance(t => t & Int.MaxValue)
  implicit val longNonNegShift: NonNegShift[Long] = instance(t => t & Long.MaxValue)
}

@armanbilge
Copy link
Contributor Author

Maybe it's not detecting the Scalacheck framework correctly when using the Cats dependency?

@lwronski
Copy link
Contributor

I reopen this issue to investigate why added scalacheck test framework isn't found by default - more info here

@lwronski lwronski reopened this Jul 27, 2022
@lwronski lwronski removed their assignment Jul 27, 2022
@tgodzik
Copy link
Member

tgodzik commented Aug 16, 2023

Let's close it with the current workaround, we don't plan to work on it.

@tgodzik tgodzik closed this as completed Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants