Skip to content

Commit 6a7d5d3

Browse files
committed
Bring back the fix for scaladoc TastyInspector regressions
Brings back the previosuly reverted commit with an added fix for the test.
1 parent 11d4295 commit 6a7d5d3

File tree

9 files changed

+60
-16
lines changed

9 files changed

+60
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ThisBuild / scalaVersion := sys.props("plugin.scalaVersion")
2+
3+
lazy val i20476 = project
4+
.in(file("i20476"))
5+
.enablePlugins(ScalaJSPlugin)
6+
7+
lazy val i18231 = project
8+
.in(file("i18231"))
9+
.settings(scalacOptions += "-release:8")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Foo {
2+
@Deprecated
3+
def foo(): Unit = ???
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package demo
2+
3+
import scala.scalajs.js
4+
5+
def bar: js.Promise[Int] = js.Promise.resolve(()).`then`(_ => 1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.scalaJSVersion"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> i18231/doc
2+
> i20476/doc

scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package tasty
55
import java.util.regex.Pattern
66

77
import scala.util.{Try, Success, Failure}
8-
import scala.tasty.inspector.{TastyInspector, Inspector, Tasty}
8+
import scala.tasty.inspector.{ScaladocInternalTastyInspector, Inspector, Tasty}
99
import scala.quoted._
1010

1111
import dotty.tools.dotc
@@ -160,7 +160,7 @@ object ScaladocTastyInspector:
160160
report.error("File extension is not `tasty` or `jar`: " + invalidPath)
161161

162162
if tastyPaths.nonEmpty then
163-
TastyInspector.inspectAllTastyFiles(tastyPaths, jarPaths, classpath)(inspector)
163+
ScaladocInternalTastyInspector.inspectAllTastyFilesInContext(tastyPaths, jarPaths, classpath)(inspector)(using ctx.compilerContext)
164164

165165
val all = inspector.topLevels.result()
166166
all.groupBy(_._1).map { case (pckName, members) =>

scaladoc/src/scala/tasty/inspector/TastyInspector.scala

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Copy of tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
1+
// Renamed copy of tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
22
// FIXME remove this copy of the file
3+
// Since copying, an inspectAllTastyFilesInContext method was added for scaladoc only
4+
// to fix regressions introduced by the switch from old to a new TastyInspector
35

46
package scala.tasty.inspector
57

@@ -21,7 +23,7 @@ import dotty.tools.dotc.report
2123

2224
import java.io.File.pathSeparator
2325

24-
object TastyInspector:
26+
object ScaladocInternalTastyInspector:
2527

2628
/** Load and process TASTy files using TASTy reflect
2729
*
@@ -41,6 +43,32 @@ object TastyInspector:
4143
def inspectTastyFilesInJar(jar: String)(inspector: Inspector): Boolean =
4244
inspectAllTastyFiles(Nil, List(jar), Nil)(inspector)
4345

46+
private def checkFiles(tastyFiles: List[String], jars: List[String]): Unit =
47+
def checkFile(fileName: String, ext: String): Unit =
48+
val file = dotty.tools.io.Path(fileName)
49+
if !file.ext.toLowerCase.equalsIgnoreCase(ext) then
50+
throw new IllegalArgumentException(s"File extension is not `.$ext`: $file")
51+
else if !file.exists then
52+
throw new IllegalArgumentException(s"File not found: ${file.toAbsolute}")
53+
tastyFiles.foreach(checkFile(_, "tasty"))
54+
jars.foreach(checkFile(_, "jar"))
55+
56+
/**
57+
* Added for Scaladoc-only.
58+
* Meant to fix regressions introduces by the switch from old to new TastyInspector:
59+
* https://github.com/scala/scala3/issues/18231
60+
* https://github.com/scala/scala3/issues/20476
61+
* Stable TastyInspector API does not support passing compiler context.
62+
*/
63+
def inspectAllTastyFilesInContext(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector)(using Context): Boolean =
64+
checkFiles(tastyFiles, jars)
65+
val classes = tastyFiles ::: jars
66+
classes match
67+
case Nil => true
68+
case _ =>
69+
val reporter = inspectorDriver(inspector).process(inspectorArgs(dependenciesClasspath, classes), summon[Context])
70+
!reporter.hasErrors
71+
4472
/** Load and process TASTy files using TASTy reflect
4573
*
4674
* @param tastyFiles List of paths of `.tasty` files
@@ -50,14 +78,7 @@ object TastyInspector:
5078
* @return boolean value indicating whether the process succeeded
5179
*/
5280
def inspectAllTastyFiles(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector): Boolean =
53-
def checkFile(fileName: String, ext: String): Unit =
54-
val file = dotty.tools.io.Path(fileName)
55-
if !file.ext.toLowerCase.equalsIgnoreCase(ext) then
56-
throw new IllegalArgumentException(s"File extension is not `.$ext`: $file")
57-
else if !file.exists then
58-
throw new IllegalArgumentException(s"File not found: ${file.toAbsolute}")
59-
tastyFiles.foreach(checkFile(_, "tasty"))
60-
jars.foreach(checkFile(_, "jar"))
81+
checkFiles(tastyFiles, jars)
6182
val files = tastyFiles ::: jars
6283
inspectFiles(dependenciesClasspath, files)(inspector)
6384

@@ -124,4 +145,4 @@ object TastyInspector:
124145
end inspectFiles
125146

126147

127-
end TastyInspector
148+
end ScaladocInternalTastyInspector

scaladoc/test/dotty/tools/scaladoc/ExternalLocationProviderIntegrationTest.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ class Scaladoc3ExternalLocationProviderIntegrationTest extends ExternalLocationP
5757

5858
def getScalaLibraryPath: String = {
5959
val classpath: List[String] = System.getProperty("java.class.path").split(java.io.File.pathSeparatorChar).toList
60-
val stdlib = classpath.find(_.contains("scala-library-2")).getOrElse("foobarbazz") // If we don't find the scala 2 library, the test will fail
61-
new java.io.File(stdlib).getCanonicalPath() // canonicalize for case-insensitive file systems
60+
// For an unclear reason, depending on if we pass the compiler context onto the tasty inspector
61+
// the scala-2-library path needs to have its characters case fixed with new java.io.File(stdlib).getCanonicalPath()
62+
classpath.find(_.contains("scala-library-2")).getOrElse("foobarbazz") // If we don't find the scala 2 library, the test will fail
6263
}
6364

6465
class Scaladoc2LegacyExternalLocationProviderIntegrationTest extends LegacyExternalLocationProviderIntegrationTest(

scaladoc/test/dotty/tools/scaladoc/no-link-warnings/LinkWarningTest.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class LinkWarningsTest extends ScaladocTest("noLinkWarnings"):
1414

1515
override def runTest = afterRendering {
1616
val diagnostics = summon[DocContext].compilerContext.reportedDiagnostics
17-
assertEquals("There should be exactly one warning", 1, diagnostics.warningMsgs.size)
17+
val filteredWarnings = diagnostics.warningMsgs.filter(_ != "1 warning found")
18+
assertEquals("There should be exactly one warning", 1, filteredWarnings.size)
1819
assertNoErrors(diagnostics)
1920
}

0 commit comments

Comments
 (0)