diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 | ||||
-rw-r--r-- | tests/neg/leaks.scala | 9 | ||||
-rw-r--r-- | tests/pos/leaks.scala | 10 |
3 files changed, 20 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index c363ee81e..0c5a8e5db 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -355,7 +355,7 @@ object Checking { var errors: Errors = Nil def accessBoundary(sym: Symbol): Symbol = - if (sym.is(Private)) sym.owner + if (sym.is(Private) || !sym.owner.isClass) sym.owner else if (sym.privateWithin.exists) sym.privateWithin else if (sym.is(Package)) sym else accessBoundary(sym.owner) diff --git a/tests/neg/leaks.scala b/tests/neg/leaks.scala index bb81d8cd2..0431c18ce 100644 --- a/tests/neg/leaks.scala +++ b/tests/neg/leaks.scala @@ -5,3 +5,12 @@ class Outer { def foo: x.type = x // error: non-private method foo refers to private value x in its type signature } } + +class Outer3Neg { + def meth: Unit = { + class Inner { + private val x: Int = 1 + def foo: x.type = x // error + } + } +} diff --git a/tests/pos/leaks.scala b/tests/pos/leaks.scala index dbb47d75a..3fe029c75 100644 --- a/tests/pos/leaks.scala +++ b/tests/pos/leaks.scala @@ -15,3 +15,13 @@ class Outer2 { def foo: Outer2.x.type = Outer2.x // OK } } + +class Outer3 { + private val x: Int = 1 + + def meth: Unit = { + class Inner { + def foo: x.type = x // OK + } + } +} |