Skip to content

Scala 2 regression: Private implicit conversion in companion object scope is not found inside companion class #14013

Closed
@neko-kai

Description

@neko-kai

Compiler version

3.1.0 and 3.1.1-RC1

Minimized code

import LightTypeTagInheritance._
// import LightTypeTagInheritance.Ctx // this doesn't work either

trait LightTypeTagRef

object LightTypeTagInheritance {
  private final case class Ctx(self: LightTypeTagInheritance) {
    def next(): Ctx = Ctx(self)
  }
  private implicit final class CtxExt(private val ctx: Ctx) extends AnyVal {
    def isChild(selfT0: LightTypeTagRef, thatT0: LightTypeTagRef): Boolean = ctx.self.isChild(ctx.next())(selfT0, thatT0)
  }
}

class LightTypeTagInheritance {
  
  def isChild(s: LightTypeTagRef, t: LightTypeTagRef): Boolean = {
    isChild(new Ctx(this))(s, t)
  }
  
  private def isChild(ctx: Ctx)(s: LightTypeTagRef, t: LightTypeTagRef): Boolean = {
    ctx.isChild(s, t)
  }
  
}

object App extends App {
  println(LightTypeTagInheritance)
}

Scastie: https://scastie.scala-lang.org/BfgPFl4wR9KewXSVPFCXFg

Output

value isChild is not a member of LightTypeTagInheritance.Ctx, but could be made available as an extension method.

The following import might fix the problem:

  import LightTypeTagInheritance.CtxExt

Expectation

Expected to compile, as in Scala 2 (https://scastie.scala-lang.org/urqciNvJRPWdhYPH8SGrjQ)

Workaround: changing CtxExt from private to private[LightTypeTagInheritance] fixes the issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions