Skip to content

Regression in recursive pickling of abstract type members #15174

Closed
@WojciechMazur

Description

@WojciechMazur

It seems that currently compiler is more strict and does not handle well recursive/lazy references to type classes. In case Codec#AvroType is not an abstract type member the snippet would compile.

Based on https://github.com/fd4s/vulcan/blob/aa857bab732b4f8b52e56473b0626b5403eef42d/modules/core/src/test/scala/vulcan/CodecSpec.scala#L1657-L1670

Compiler version

3.1.2, works with 3.1.1

First bad commit ae1b00d

Minimized code

//> using scala "3.1.2"
// //> using scala "3.1.1" // Last stable working version

trait Error
sealed abstract class Codec[A] {
  type AvroType
  def encode(a: A): Either[Error, AvroType]
  def decode(value: Any): Either[Error, A]
}

object Codec {
  type Aux[AvroType0, A] = Codec[A] {
    type AvroType = AvroType0
  }

  final def instance[AvroType0, A](
      encode: A => Either[Error, AvroType0],
      decode: Any => Either[Error, A]
  ): Codec.Aux[AvroType0, A]  = ???

  implicit final def option[A](implicit codec: Codec[A]): Codec[Option[A]] = ???
  given Codec.Aux[Int, Int] = ???
}


@main def test() = {
  implicit val codec: Codec[Option[Int]] =
    Codec.instance(
      Codec.option[Int].encode,
      Codec.option[Int].decode
    )
}

Output

[error] ./test.scala:29:7: pickling reference to as yet undefined ($1$ : Codec[Option[Int]]) with symbol value $1$
[error]       Codec.option[Int].encode,
[error]       ^
Error compiling project (Scala 3.1.2, JVM)

Expectation

The snippet should compile like in the 3.1.1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions