Skip to content

class LazyDefns$1 requires premature access error using by-name implicits and subclasses #12574

Open
@mrdziuban

Description

@mrdziuban

Reproduction steps

Scala version: 2.13.8

trait ByNameImplicit[A, B]
object ByNameImplicit {
  implicit def invert[A, B](implicit ab: => ByNameImplicit[A, B]): ByNameImplicit[B, A] =
    new ByNameImplicit[B, A] {}
}

abstract class Class1[A](implicit val byNameImpl: ByNameImplicit[A, A])
abstract class Class2 extends Class1[Int]
// Implementation restriction: class LazyDefns$1 requires premature access to class Class2.

Here's the same code in a scastie: https://scastie.scala-lang.org/mrdziuban/KhMLbN5dSQCMIbaQARLN7g/1

Problem

I'm not 100% sure what's expected here, but the error caught me off guard. It didn't point to any particular code so I only determined it was related to by-name implicits by googling and finding mention of LazyDefns$1 in the documentation for implicits.

For what it's worth, the error does not happen with Scala 3.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bynamefixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)implicit

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions