Skip to content

Commit ca2b2d5

Browse files
committed
Use a different encoding for constructor: constructor.enclosingClass.fullName ++ ";init;"
1 parent e4eed7b commit ca2b2d5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ class ExtractDependencies extends Phase {
151151
object ExtractDependencies {
152152
def classNameAsString(sym: Symbol)(implicit ctx: Context): String =
153153
sym.fullName.stripModuleClassSuffix.toString
154-
155-
/** Return the enclosing class or the module class if it's a module. */
156-
def enclOrModuleClass(dep: Symbol)(implicit ctx: Context): Symbol =
157-
if (dep.is(ModuleVal)) dep.moduleClass else dep.enclosingClass
158154
}
159155

160156
private case class ClassDependency(from: Symbol, to: Symbol, context: DependencyContext)
@@ -230,7 +226,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
230226
if (_responsibleForImports == null) {
231227
val tree = ctx.compilationUnit.tpdTree
232228
_responsibleForImports = firstClassOrModule(tree)
233-
if (_responsibleForImports == NoSymbol)
229+
if (!_responsibleForImports.exists)
234230
ctx.warning("""|No class, trait or object is defined in the compilation unit.
235231
|The incremental compiler cannot record the dependency information in such case.
236232
|Some errors like unused import referring to a non-existent class might not be reported.
@@ -274,24 +270,32 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
274270

275271
private def addUsedName(name: Name, scope: UseScope)(implicit ctx: Context): Unit = {
276272
val fromClass = resolveDependencySource
277-
if (fromClass ne NoSymbol) {
273+
if (fromClass.exists) {
278274
assert(fromClass.isClass)
279275
addUsedName(fromClass, name, scope)
280276
}
281277
}
282278

279+
/** Mangle a JVM symbol name in a format better suited for internal uses by sbt. */
280+
private def mangledName(sym: Symbol)(implicit ctx: Context): Name = {
281+
def constructorName = sym.enclosingClass.fullName ++ ";init;"
282+
283+
if (sym.isConstructor) constructorName
284+
else sym.name.stripModuleClassSuffix
285+
}
286+
283287
private def addMemberRefDependency(sym: Symbol)(implicit ctx: Context): Unit =
284288
if (!ignoreDependency(sym)) {
285-
val depClass = enclOrModuleClass(sym)
286-
// assert(depClass.isClass, s"$depClass, $sym, ${sym.isClass}")
289+
val enclOrModuleClass = if (sym.is(ModuleVal)) sym.moduleClass else sym.enclosingClass
290+
// assert(enclOrModuleClass.isClass, s"$depClass, $sym"))
287291

288-
if (depClass ne NoSymbol) {
289-
assert(depClass.isClass)
292+
if (enclOrModuleClass.exists) {
293+
assert(enclOrModuleClass.isClass)
290294
val fromClass = resolveDependencySource
291-
if (fromClass ne NoSymbol) {
295+
if (fromClass.exists) {
292296
assert(fromClass.isClass)
293-
_dependencies += ClassDependency(fromClass, depClass, DependencyByMemberRef)
294-
addUsedName(fromClass, sym.name.stripModuleClassSuffix, UseScope.Default)
297+
_dependencies += ClassDependency(fromClass, enclOrModuleClass, DependencyByMemberRef)
298+
addUsedName(fromClass, mangledName(sym), UseScope.Default)
295299
}
296300
}
297301
}
@@ -308,7 +312,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
308312
}
309313

310314
private def ignoreDependency(sym: Symbol)(implicit ctx: Context) =
311-
sym.eq(NoSymbol) ||
315+
!sym.exists ||
312316
sym.isAnonymousFunction ||
313317
sym.isAnonymousClass ||
314318
sym.is(PackageClass)
@@ -424,7 +428,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
424428
val traverser = new TypeDependencyTraverser {
425429
def addDependency(symbol: Symbol) =
426430
if (!ignoreDependency(symbol) && symbol.is(Sealed)) {
427-
val usedName = symbol.name.stripModuleClassSuffix
431+
val usedName = mangledName(symbol)
428432
addUsedName(usedName, UseScope.PatMatTarget)
429433
}
430434
}

sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class ExtractUsedNamesSpecification {
310310
// The default parent of a class is "AnyRef" which is an alias for "Object"
311311
"AnyRef",
312312
"Object",
313-
"java;lang;Object;init;"
313+
"java.lang.Object;init;"
314314
)
315315

316316
}

0 commit comments

Comments
 (0)