Skip to content

Commit 3d79b98

Browse files
committed
Restrict access to the classloader to Context only.
1 parent 7527d5d commit 3d79b98

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ lazy val tastyQuery =
127127
import com.typesafe.tools.mima.core.*
128128
Seq(
129129
// private[tastyquery], not an issue
130+
ProblemFilters.exclude[DirectMissingMethodProblem]("tastyquery.Contexts#Context.classloader"),
130131
ProblemFilters.exclude[MissingClassProblem]("tastyquery.Utils"),
131132
ProblemFilters.exclude[MissingClassProblem]("tastyquery.Utils$"),
132133
// private, not an issue

tasty-query/shared/src/main/scala/tastyquery/Contexts.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ object Contexts {
5858
* The same instance of [[Classpaths.Classpath]] can be reused to create
5959
* several [[Context]]s, if necessary.
6060
*/
61-
final class Context private[Contexts] (private[tastyquery] val classloader: Loader) {
61+
final class Context private[Contexts] (classloader: Loader) {
6262
private given Context = this
6363

6464
private val sourceFiles = mutable.HashMap.empty[String, SourceFile]
6565

6666
private val (RootPackage @ _, EmptyPackage @ _) = PackageSymbol.createRoots()
6767

68+
private[tastyquery] def hasGenericTuples: Boolean = classloader.hasGenericTuples
69+
6870
val defn: Definitions = Definitions(this: @unchecked, RootPackage, EmptyPackage)
6971

72+
private[tastyquery] def internalClasspathForTestsOnly: Classpath = classloader.classpath
73+
7074
private[tastyquery] def getSourceFile(path: String): SourceFile =
7175
sourceFiles.getOrElseUpdate(path, new SourceFile(path))
7276

tasty-query/shared/src/main/scala/tastyquery/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ final class Definitions private[tastyquery] (
517517
end functionClassOf
518518
end PolyFunctionType
519519

520-
lazy val hasGenericTuples = withRestrictedContext(ctx.classloader.hasGenericTuples)
520+
lazy val hasGenericTuples = withRestrictedContext(ctx.hasGenericTuples)
521521

522522
lazy val uninitializedMethod: Option[TermSymbol] =
523523
withRestrictedContext {

tasty-query/shared/src/main/scala/tastyquery/reader/ReaderContext.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private[reader] final class ReaderContext(underlying: Context):
6969
def getSourceFile(path: String): SourceFile =
7070
underlying.getSourceFile(path)
7171

72-
def hasGenericTuples: Boolean = underlying.classloader.hasGenericTuples
72+
def hasGenericTuples: Boolean = underlying.hasGenericTuples
7373

7474
def createObjectMagicMethods(cls: ClassSymbol): Unit =
7575
underlying.defn.createObjectMagicMethods(cls)

tasty-query/shared/src/test/scala/tastyquery/ClasspathEntrySuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import tastyquery.testutil.TestPlatform
99
class ClasspathEntrySuite extends UnrestrictedUnpicklingSuite:
1010

1111
def scala3ClasspathEntry(using Context): ClasspathEntry =
12-
ctx.classloader.classpath(TestPlatform.scala3ClasspathIndex)
12+
ctx.internalClasspathForTestsOnly(TestPlatform.scala3ClasspathIndex)
1313

1414
def lookupSyms(entry: ClasspathEntry)(using Context): IArray[Symbol] =
1515
IArray.from(ctx.findSymbolsByClasspathEntry(entry))

0 commit comments

Comments
 (0)