Skip to content

Commit 4a74fb7

Browse files
committed
Strip module suffix for module class
Zinc relies on class and its companion class having the same name: this creates an implicit dependency between the two.
1 parent a2d86e8 commit 4a74fb7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
207207

208208
val selfType = apiType(sym.givenSelfType)
209209

210-
val name = sym.fullName.toString
210+
val name = sym.fullName.stripModuleClassSuffix.toString
211+
// We strip module class suffix. Zinc relies on a class and its companion having the same name
211212

212213
val tparams = sym.typeParams.map(apiTypeParameter).toArray
213214

@@ -241,7 +242,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder
241242

242243
val javaPlatform = ctx.platform.asInstanceOf[JavaPlatform]
243244
if (sym.isStatic && defType == DefinitionType.Module && javaPlatform.hasJavaMainMethod(sym)) {
244-
_mainClasses += sym.fullName.stripModuleClassSuffix.toString // required for sbt to find the static main method
245+
_mainClasses += name
245246
}
246247

247248
api.ClassLikeDef.of(name, acc, modifiers, anns, tparams, defType)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class ExtractDependencies extends Phase {
179179

180180
object ExtractDependencies {
181181
def classNameAsString(sym: Symbol)(implicit ctx: Context): String =
182-
sym.fullName.toString
182+
sym.fullName.stripModuleClassSuffix.toString
183183

184184
def isLocal(sym: Symbol)(implicit ctx: Context): Boolean =
185185
sym.ownersIterator.exists(_.isTerm)
@@ -269,7 +269,7 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
269269
_topLevelDependencies += ClassDependency(currentClass, tlClass)
270270
}
271271
}
272-
addUsedName(nonLocalEnclosingClass(ctx.owner), sym.name)
272+
addUsedName(nonLocalEnclosingClass(ctx.owner), sym.name.stripModuleClassSuffix)
273273
}
274274

275275
private def nonLocalEnclosingClass(sym: Symbol)(implicit ctx: Context): Symbol =
@@ -294,7 +294,7 @@ private class ExtractDependenciesCollector(responsibleForImports: Symbol)(implic
294294
private class PatMatDependencyTraverser(ctx0: Context) extends ExtractTypesCollector(ctx0) {
295295
override protected def addDependency(symbol: Symbol)(implicit ctx: Context): Unit = {
296296
if (!ignoreDependency(symbol) && symbol.is(Sealed)) {
297-
val encName = nonLocalEnclosingClass(ctx.owner).fullName.toString
297+
val encName = nonLocalEnclosingClass(ctx.owner).fullName.stripModuleClassSuffix.toString
298298
val nameUsed = _usedNames.getOrElseUpdate(encName, new NameUsedInClass)
299299

300300
nameUsed.defaultNames += symbol.name

0 commit comments

Comments
 (0)