From accf42d555a6754a620b56fbaec604df1d89a469 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 28 Apr 2024 00:07:47 -0400 Subject: [PATCH] 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. --- .../src/dotty/tools/dotc/sbt/ExtractAPI.scala | 2 +- .../tools/dotc/sbt/ExtractDependencies.scala | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 75f04908ac55..75e859111932 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -295,7 +295,7 @@ private class ExtractAPICollector(nonLocalClassSymbols: mutable.HashSet[Symbol]) val selfType = apiType(sym.givenSelfType) - val name = sym.fullName.stripModuleClassSuffix.toString + val name = ExtractDependencies.classNameAsString(sym) // We strip module class suffix. Zinc relies on a class and its companion having the same name val tparams = sym.typeParams.map(apiTypeParameter).toArray diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index dfff5971889e..154d50f8ebc2 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -105,8 +105,24 @@ object ExtractDependencies { val name: String = "sbt-deps" val description: String = "sends information on classes' dependencies to sbt" + /** Construct String name for the given sym. + * See https://github.com/sbt/zinc/blob/v1.9.6/internal/zinc-apiinfo/src/main/scala/sbt/internal/inc/ClassToAPI.scala#L86-L99 + * + * For a Java nested class M of a class C returns C's canonical name + "." + M's simple name. + */ def classNameAsString(sym: Symbol)(using Context): String = - sym.fullName.stripModuleClassSuffix.toString + def isJava(sym: Symbol)(using Context): Boolean = + Option(sym.source) match + case Some(src) => src.toString.endsWith(".java") + case None => false + def classNameAsString0(sym: Symbol)(using Context): String = + sym.fullName.stripModuleClassSuffix.toString + def javaClassNameAsString(sym: Symbol)(using Context): String = + if sym.owner.isClass && !sym.owner.isRoot then + javaClassNameAsString(sym.owner) + "." + sym.name.stripModuleClassSuffix.toString + else classNameAsString0(sym) + if isJava(sym) then javaClassNameAsString(sym) + else classNameAsString0(sym) /** Report an internal error in incremental compilation. */ def internalError(msg: => String, pos: SrcPos = NoSourcePosition)(using Context): Unit =