Skip to content

Also consider private symbols in implicit scope of type #14054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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%, %."
Expand Down
15 changes: 15 additions & 0 deletions tests/neg/i14013.scala
Original file line number Diff line number Diff line change
@@ -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)
}
63 changes: 63 additions & 0 deletions tests/pos/i14013.scala
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was marked as scala2-compat, is this behavior something we also want with givens?

Should this one be visible in class Foo?

private given BarOps: AnyRef with {
    extension (bar: Bar)
      def twice: Bar = Bar(bar.i * 2)
  }

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)
}