Skip to content

Commit 36373f2

Browse files
eed3si9nWojciechMazur
authored andcommitted
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. [Cherry-picked accf42d]
1 parent 6550e49 commit 36373f2

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
@@ -229,7 +229,7 @@ private class ExtractAPICollector(using Context) extends ThunkHolder {
229229

230230
val selfType = apiType(sym.givenSelfType)
231231

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

235235
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
@@ -149,8 +149,24 @@ object ExtractDependencies {
149149
val name: String = "sbt-deps"
150150
val description: String = "sends information on classes' dependencies to sbt"
151151

152+
/** Construct String name for the given sym.
153+
* See https://github.com/sbt/zinc/blob/v1.9.6/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala#L86-L99
154+
*
155+
* For a Java nested class M of a class C returns C's canonical name + "." + M's simple name.
156+
*/
152157
def classNameAsString(sym: Symbol)(using Context): String =
153-
sym.fullName.stripModuleClassSuffix.toString
158+
def isJava(sym: Symbol)(using Context): Boolean =
159+
Option(sym.source) match
160+
case Some(src) => src.toString.endsWith(".java")
161+
case None => false
162+
def classNameAsString0(sym: Symbol)(using Context): String =
163+
sym.fullName.stripModuleClassSuffix.toString
164+
def javaClassNameAsString(sym: Symbol)(using Context): String =
165+
if sym.owner.isClass && !sym.owner.isRoot then
166+
javaClassNameAsString(sym.owner) + "." + sym.name.stripModuleClassSuffix.toString
167+
else classNameAsString0(sym)
168+
if isJava(sym) then javaClassNameAsString(sym)
169+
else classNameAsString0(sym)
154170

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

0 commit comments

Comments
 (0)