diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index d7bf75f8bf73..25433343e629 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -287,7 +287,7 @@ object Implicits: } override def isAccessible(ref: TermRef)(using Context): Boolean = - ref.symbol.exists && !ref.symbol.is(Private) + ref.symbol.exists override def toString: String = i"OfTypeImplicits($tp), companions = ${companionRefs.showAsList}%, %; refs = $refs%, %." diff --git a/tests/neg/i14013.scala b/tests/neg/i14013.scala new file mode 100644 index 000000000000..96b2e7c0cdd7 --- /dev/null +++ b/tests/neg/i14013.scala @@ -0,0 +1,15 @@ +object Foo1 { + case class Bar(i: Int) + + private implicit class BarOps(bar: Bar) { + def twice = Bar(bar.i * 2) + } +} + +class Foo { + def bar = Foo.Bar(1).twice // error +} + +object App extends App { + println((new Foo).bar) +} \ No newline at end of file diff --git a/tests/pos/i14013.scala b/tests/pos/i14013.scala new file mode 100644 index 000000000000..d20112392002 --- /dev/null +++ b/tests/pos/i14013.scala @@ -0,0 +1,63 @@ +import LightTypeTagInheritance._ + +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) +} + + +object Foo { + case class Bar(i: Int) + + private implicit class BarOps(bar: Bar) { + def twice = Bar(bar.i * 2) + } +} + +class Foo { + def bar = Foo.Bar(1).twice +} + +object App2 extends App { + println((new Foo).bar) +} + +object Foo2 { + case class Bar(i: Int) + + private given BarOps: AnyRef with { + extension (bar: Bar) + def twice: Bar = Bar(bar.i * 2) + } +} + +class Foo2 { + def bar = Foo2.Bar(1).twice +} + +object App3 extends App { + println((new Foo2).bar) +} +