Skip to content

Commit 6759a8b

Browse files
committed
Adjust the API name entry for nested classes
**Problem** Some build pipelining tests fail on the latest sbt RC. ``` Error: (sbt-test / scripted) Failed tests: Error: pipelining/Yjava-tasty-fromjavaobject Error: pipelining/Yjava-tasty-paths ``` This is likely caused by inconsistent capturing of APIs from Java sources in ExtractAPI vs AnalyzingJavaCompiler in Zinc. **Solution** This adjusts the API name entry for Java nested classes.
1 parent 44c1e3a commit 6759a8b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private class ExtractAPICollector(nonLocalClassSymbols: mutable.HashSet[Symbol])
295295

296296
val selfType = apiType(sym.givenSelfType)
297297

298-
val name = sym.fullName.stripModuleClassSuffix.toString
298+
val name = ExtractDependencies.classNameAsString(sym)
299299
// We strip module class suffix. Zinc relies on a class and its companion having the same name
300300

301301
val tparams = sym.typeParams.map(apiTypeParameter).toArray

Diff for: compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

+17-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,24 @@ object ExtractDependencies {
105105
val name: String = "sbt-deps"
106106
val description: String = "sends information on classes' dependencies to sbt"
107107

108+
/** Construct String name for the given sym.
109+
* See https://github.com/sbt/zinc/blob/v1.9.6/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala#L86-L99
110+
*
111+
* For a Java nested class M of a class C returns C's canonical name + "." + M's simple name.
112+
*/
108113
def classNameAsString(sym: Symbol)(using Context): String =
109-
sym.fullName.stripModuleClassSuffix.toString
114+
def isJava(sym: Symbol)(using Context): Boolean =
115+
Option(sym.source) match
116+
case Some(src) => src.toString.endsWith(".java")
117+
case None => false
118+
def classNameAsString0(sym: Symbol)(using Context): String =
119+
sym.fullName.stripModuleClassSuffix.toString
120+
def javaClassNameAsString(sym: Symbol)(using Context): String =
121+
if sym.owner.isClass && !sym.owner.isRoot then
122+
javaClassNameAsString(sym.owner) + "." + sym.name.stripModuleClassSuffix.toString
123+
else classNameAsString0(sym)
124+
if isJava(sym) then javaClassNameAsString(sym)
125+
else classNameAsString0(sym)
110126

111127
/** Report an internal error in incremental compilation. */
112128
def internalError(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =

0 commit comments

Comments
 (0)