Skip to content

Commit 21935f9

Browse files
committed
checkNoPrivateLeaks: handle defs in local classes
The access boundary of a def in a local class is the owner of that class, previously it was set to the access boundary of the owner of the class instead.
1 parent 0412f51 commit 21935f9

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ object Checking {
355355
var errors: Errors = Nil
356356

357357
def accessBoundary(sym: Symbol): Symbol =
358-
if (sym.is(Private)) sym.owner
358+
if (sym.is(Private) || !sym.owner.isClass) sym.owner
359359
else if (sym.privateWithin.exists) sym.privateWithin
360360
else if (sym.is(Package)) sym
361361
else accessBoundary(sym.owner)

tests/neg/leaks.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ class Outer {
55
def foo: x.type = x // error: non-private method foo refers to private value x in its type signature
66
}
77
}
8+
9+
class Outer3Neg {
10+
def meth: Unit = {
11+
class Inner {
12+
private val x: Int = 1
13+
def foo: x.type = x // error
14+
}
15+
}
16+
}

tests/pos/leaks.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ class Outer2 {
1515
def foo: Outer2.x.type = Outer2.x // OK
1616
}
1717
}
18+
19+
class Outer3 {
20+
private val x: Int = 1
21+
22+
def meth: Unit = {
23+
class Inner {
24+
def foo: x.type = x // OK
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)