Skip to content

Commit 7a47334

Browse files
authored
Merge pull request #14054 from dotty-staging/fix-14013
Also consider private symbols in implicit scope of type
2 parents fee34a9 + f3f9e79 commit 7a47334

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ object Implicits:
288288
}
289289

290290
override def isAccessible(ref: TermRef)(using Context): Boolean =
291-
ref.symbol.exists && !ref.symbol.is(Private)
291+
ref.symbol.exists
292292

293293
override def toString: String =
294294
i"OfTypeImplicits($tp), companions = ${companionRefs.showAsList}%, %; refs = $refs%, %."

tests/neg/i14013.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object Foo1 {
2+
case class Bar(i: Int)
3+
4+
private implicit class BarOps(bar: Bar) {
5+
def twice = Bar(bar.i * 2)
6+
}
7+
}
8+
9+
class Foo {
10+
def bar = Foo.Bar(1).twice // error
11+
}
12+
13+
object App extends App {
14+
println((new Foo).bar)
15+
}

tests/pos/i14013.scala

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import LightTypeTagInheritance._
2+
3+
trait LightTypeTagRef
4+
5+
object LightTypeTagInheritance {
6+
private final case class Ctx(self: LightTypeTagInheritance) {
7+
def next(): Ctx = Ctx(self)
8+
}
9+
private implicit final class CtxExt(private val ctx: Ctx) extends AnyVal {
10+
def isChild(selfT0: LightTypeTagRef, thatT0: LightTypeTagRef): Boolean = ctx.self.isChild(ctx.next())(selfT0, thatT0)
11+
}
12+
}
13+
14+
class LightTypeTagInheritance {
15+
16+
def isChild(s: LightTypeTagRef, t: LightTypeTagRef): Boolean = {
17+
isChild(new Ctx(this))(s, t)
18+
}
19+
20+
private def isChild(ctx: Ctx)(s: LightTypeTagRef, t: LightTypeTagRef): Boolean = {
21+
ctx.isChild(s, t)
22+
}
23+
24+
}
25+
26+
object App extends App {
27+
println(LightTypeTagInheritance)
28+
}
29+
30+
31+
object Foo {
32+
case class Bar(i: Int)
33+
34+
private implicit class BarOps(bar: Bar) {
35+
def twice = Bar(bar.i * 2)
36+
}
37+
}
38+
39+
class Foo {
40+
def bar = Foo.Bar(1).twice
41+
}
42+
43+
object App2 extends App {
44+
println((new Foo).bar)
45+
}
46+
47+
object Foo2 {
48+
case class Bar(i: Int)
49+
50+
private given BarOps: AnyRef with {
51+
extension (bar: Bar)
52+
def twice: Bar = Bar(bar.i * 2)
53+
}
54+
}
55+
56+
class Foo2 {
57+
def bar = Foo2.Bar(1).twice
58+
}
59+
60+
object App3 extends App {
61+
println((new Foo2).bar)
62+
}
63+

0 commit comments

Comments
 (0)