scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

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

Open armanbilge opened this issue 3 years ago • 5 comments

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)
}

armanbilge avatar Jul 06 '22 22:07 armanbilge

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?

lwronski avatar Jul 15 '22 11:07 lwronski

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

armanbilge avatar Jul 15 '22 11:07 armanbilge

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)
}

lwronski avatar Jul 19 '22 08:07 lwronski

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

armanbilge avatar Jul 19 '22 14:07 armanbilge

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

lwronski avatar Jul 27 '22 13:07 lwronski

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

tgodzik avatar Aug 16 '23 09:08 tgodzik