From cdbf1ea7d9cef86561db6ee9ec1a84798e4d4762 Mon Sep 17 00:00:00 2001 From: Mason Edmison Date: Thu, 12 Sep 2024 09:49:39 -0500 Subject: [PATCH] (Scala3) Delegate to SymDenotation#isAccessibleFrom for accessibility check --- .../internal/pc/CompilerSearchVisitor.scala | 2 +- .../ImportMissingSymbolCrossLspSuite.scala | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala index feb6c62931e..13a356a506a 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala @@ -28,7 +28,7 @@ class CompilerSearchVisitor( owner.isStatic && owner.isPublic private def isAccessible(sym: Symbol): Boolean = try - sym != NoSymbol && sym.isPublic && sym.isStatic || + sym.isAccessibleFrom(ctx.owner.info) || isAccessibleImplicitClass(sym) catch case err: AssertionError => diff --git a/tests/slow/src/test/scala/tests/feature/ImportMissingSymbolCrossLspSuite.scala b/tests/slow/src/test/scala/tests/feature/ImportMissingSymbolCrossLspSuite.scala index 7eea38fc54e..7c0713da134 100644 --- a/tests/slow/src/test/scala/tests/feature/ImportMissingSymbolCrossLspSuite.scala +++ b/tests/slow/src/test/scala/tests/feature/ImportMissingSymbolCrossLspSuite.scala @@ -230,4 +230,64 @@ class ImportMissingSymbolCrossLspSuite scalaVersion = V.scala3, ) + check( + "i6732-happy", + s"""|package example.a { + | private [example] object A { + | val foo = "foo" + | } + |} + |package example.b { + | object B { + | val bar = <>.foo + | } + |} + |""".stripMargin, + s"""|${ImportMissingSymbol.title("A", "example.a")} + |${CreateNewSymbol.title("A")} + |""".stripMargin, + s"""|import example.a.A + |package example.a { + | private [example] object A { + | val foo = "foo" + | } + |} + |package example.b { + | object B { + | val bar = A.foo + | } + |} + |""".stripMargin, + scalaVersion = V.scala3, + ) + + check( + "i6732-negative (private)", + s"""|package example.a { + | private object A { + | val foo = "foo" + | } + |} + |package example.b { + | object B { + | val bar = <> + | } + |} + |""".stripMargin, + "", + s"""|package example.a { + | private object A { + | val foo = "foo" + | } + |} + |package example.b { + | object B { + | val bar = A + | } + |} + |""".stripMargin, + expectNoDiagnostics = false, + filterAction = _.getTitle() == ImportMissingSymbol.title("A", "example.a"), + scalaVersion = V.scala3, + ) }