Skip to content

Typechecking regression in v3.1.2 #15178

Closed
@tnielens

Description

@tnielens

Compiler version

Works with v3.1.1, fails with v3.1.2 and v3.1.3-RC3.

First bad commit 3ab18a9

Minimized code

//> using scala "3.1.1"
//> using lib "org.scalacheck::scalacheck:1.16.0"
import scala.reflect.ClassTag
import org.scalacheck.Arbitrary
import org.scalacheck.Gen

trait E[F[_]] {
  type T
  val value: F[T]
  override def toString(): String = s"E($value)"
}

object E {
  def apply[F[_], T1](value1: F[T1]) = new E[F] {
    type T = T1
    val value = value1
  }
}

trait TaggedGen[T] {
  val tag: ClassTag[T]
  val gen: Gen[T]
  override def toString(): String = s"TaggedGen($tag, $gen)"
}
type ETaggedGen = E[TaggedGen]

object TaggedGen {
  def apply[T: ClassTag: Arbitrary] = new TaggedGen[T] {
    val tag = implicitly
    val gen = implicitly[Arbitrary[T]].arbitrary
  }

  def apply[T](tag1: ClassTag[T], gen1: Gen[T]) = new TaggedGen[T] {
    val tag = tag1
    val gen = gen1
  }

  val gen: Gen[ETaggedGen] =
    Gen.oneOf(
      E(apply[Boolean]),
      E(apply[Byte]),
      E(apply[String])
    )

  val gen2: Gen[ETaggedGen] =
    gen.map { etg =>
      implicit val tag = etg.value.tag
      E(TaggedGen(tag, etg.value.gen.filter(_ => true))) // <-- failure here
    }
}

Output

[error] ./test.sc:54:19: Found:    (tag : reflect.ClassTag[etg.T])
[error] Required: reflect.ClassTag[Any]
[error]       E(TaggedGen(tag, etg.value.gen.filter(_ => true)))
[error]                   ^^^
Error compiling project (Scala 3.1.2, JVM)

Expectation

This snippet should continue compiling with scala v3.1.2.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions