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 1 commit
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)
}
15 changes: 15 additions & 0 deletions tests/pos/i14013.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 App extends App {
println((new Foo).bar)
}