From ff83d77b7cad7173e9a934c0503798ce8a796dea Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 15 Jan 2020 13:06:34 +0100 Subject: [PATCH 1/2] Fix #7959: Don't check Java symbols for private leaks Java does not have the same rules as Scala here. Also, there are problems with package[private] which is translated to private[pkg]. In the test case, the constructor is assumed to be visible up to the package (because it is always annotated as such) which is further than the enclosing private class. --- compiler/src/dotty/tools/dotc/core/Flags.scala | 1 + compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala | 3 ++- tests/pos/i7959.java | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i7959.java diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index b1ec95a0e7c3..e3d907d6abd6 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -544,6 +544,7 @@ object Flags { val InlineByNameProxy: FlagSet = InlineProxy | Method val JavaEnumTrait: FlagSet = JavaDefined | Enum // A Java enum trait val JavaEnumValue: FlagSet = JavaDefined | EnumValue // A Java enum value + val JavaOrPrivateOrSynthetic: FlagSet = JavaDefined | Private | Synthetic val StaticProtected: FlagSet = JavaDefined | JavaStatic | Protected // Java symbol which is `protected` and `static` val JavaModule: FlagSet = JavaDefined | Module // A Java companion object val JavaInterface: FlagSet = JavaDefined | NoInits | Trait diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 07883266ac73..34ea152e6f30 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -161,7 +161,8 @@ trait TypeAssigner { avoid(expr.tpe, localSyms(bindings).filter(_.isTerm)) def avoidPrivateLeaks(sym: Symbol)(implicit ctx: Context): Type = - if (!sym.isOneOf(PrivateOrSynthetic) && sym.owner.isClass) checkNoPrivateLeaks(sym) + if sym.owner.isClass && !sym.isOneOf(JavaOrPrivateOrSynthetic) + then checkNoPrivateLeaks(sym) else sym.info private def toRepeated(tree: Tree, from: ClassSymbol)(implicit ctx: Context): Tree = diff --git a/tests/pos/i7959.java b/tests/pos/i7959.java new file mode 100644 index 000000000000..161e35b7eebf --- /dev/null +++ b/tests/pos/i7959.java @@ -0,0 +1,5 @@ +public class Test { + private static class Foo { + Foo() { } + } +} \ No newline at end of file From a8d069bc086ba1f92c9f859986323d4149e45fd0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 15 Jan 2020 18:22:48 +0100 Subject: [PATCH 2/2] Fix Java class name in test --- tests/pos/i7959.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pos/i7959.java b/tests/pos/i7959.java index 161e35b7eebf..5ec2c4f4de8c 100644 --- a/tests/pos/i7959.java +++ b/tests/pos/i7959.java @@ -1,4 +1,4 @@ -public class Test { +public class i7959 { private static class Foo { Foo() { } }