Scala 2 regression: Private implicit conversion in companion object scope is not found inside companion class
See original GitHub issueCompiler 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Implicit conversion declared in companion object is not called
So, compiler tries to find implicit conversion from "Fraction to Int" in "Int" type first. As "Int" type does not have any implementation...
Read more >implicit object on a companion is not found in implicit scope
I suspect this could be one of two things: object is treated separately to val; the object is a type in its own...
Read more >Chapter 5. Using implicits to write expressive code - Scala in ...
The Scala compiler can infer one of two situations: A method call or constructor with a missing parameter. Missing conversion from one type...
Read more >Ammonite
Ammonite provides a set of magic imports that let you load additional code into a REPL session: these are imports which start with...
Read more >Kotlin Language Documentation 1.7.21
Extension properties. Companion object extensions. Scope of extensions. Declaring extensions as members. Note on visibility. Data classes.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Minimized example:
Interestingly this works if you move
import LightTypeTagInheritance._
from the top level to the inside ofclass LightTypeTagInheritance
. Honestly speaking I’m not sure if this is a bug or a feature.