From d49fdb881e234558adf156b067d885501573d99d Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:18:00 -0800 Subject: [PATCH] Add scripted test for #1507 --- .../test/scala/sbt/internal/inc/IncHandler.scala | 11 +++++++++++ .../anon-class-dep/A/Refined.scala | 8 ++++++++ .../anon-class-dep/B/Client.scala | 7 +++++++ .../source-dependencies/anon-class-dep/build.json | 15 +++++++++++++++ .../source-dependencies/anon-class-dep/test | 2 ++ 5 files changed, 43 insertions(+) create mode 100644 zinc/src/sbt-test/source-dependencies/anon-class-dep/A/Refined.scala create mode 100644 zinc/src/sbt-test/source-dependencies/anon-class-dep/B/Client.scala create mode 100644 zinc/src/sbt-test/source-dependencies/anon-class-dep/build.json create mode 100644 zinc/src/sbt-test/source-dependencies/anon-class-dep/test diff --git a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala index 8b8d19305..a8da05cb2 100644 --- a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala +++ b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala @@ -225,6 +225,9 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co onArgs("checkIterations") { case (p, x :: Nil, i) => p.checkNumberOfCompilerIterations(i, x.toInt) }, + onArgs("checkNumberOfLibraries") { + case (p, x :: Nil, i) => p.checkNumberOfLibraries(i, x.toInt) + }, onArgs("checkCycles") { case (p, x :: Nil, i) => p.checkNumberOfCycles(i, x.toInt) }, @@ -525,6 +528,14 @@ case class ProjectStructure( () } + def checkNumberOfLibraries(i: IncState, expected: Int): Future[Unit] = + compile(i).map { analysis => + val count = analysis.stamps.libraries.size + val msg = s"analysis.stamps.libraries.size = $count (expected $expected)" + assert(count == expected, msg) + () + } + def run(i: IncState, params: Seq[String]): Future[Unit] = compile(i).map { analysis => discoverMainClasses(Some(analysis.apis)) match { diff --git a/zinc/src/sbt-test/source-dependencies/anon-class-dep/A/Refined.scala b/zinc/src/sbt-test/source-dependencies/anon-class-dep/A/Refined.scala new file mode 100644 index 000000000..01a3272d3 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/anon-class-dep/A/Refined.scala @@ -0,0 +1,8 @@ +package A + +class SRC[_] +class Refined { + def select() = new { + def using(opt: Option[SRC[_]] => Some[SRC[_]]) = opt + } +} diff --git a/zinc/src/sbt-test/source-dependencies/anon-class-dep/B/Client.scala b/zinc/src/sbt-test/source-dependencies/anon-class-dep/B/Client.scala new file mode 100644 index 000000000..f8845ec20 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/anon-class-dep/B/Client.scala @@ -0,0 +1,7 @@ +package B + +import A.Refined + +class Client { + def temp = new Refined().select().using(null) +} diff --git a/zinc/src/sbt-test/source-dependencies/anon-class-dep/build.json b/zinc/src/sbt-test/source-dependencies/anon-class-dep/build.json new file mode 100644 index 000000000..7903253bc --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/anon-class-dep/build.json @@ -0,0 +1,15 @@ +{ + "projects": [ + { + "name": "B", + "dependsOn": [ + "A" + ], + "scalaVersion": "2.13.x" + }, + { + "name": "A", + "scalaVersion": "2.13.x" + } + ] +} diff --git a/zinc/src/sbt-test/source-dependencies/anon-class-dep/test b/zinc/src/sbt-test/source-dependencies/anon-class-dep/test new file mode 100644 index 000000000..35d2efc06 --- /dev/null +++ b/zinc/src/sbt-test/source-dependencies/anon-class-dep/test @@ -0,0 +1,2 @@ +> B/compile +> B/checkNumberOfLibraries 1