Skip to content

Commit

Permalink
Merge pull request #1507 from retronym/anon-dep
Browse files Browse the repository at this point in the history
Exclude anon classes from dependency registration
  • Loading branch information
eed3si9n authored Dec 6, 2024
2 parents 5ca7ed7 + c752dae commit e2f5ea1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
* but when it does we must ensure the incremental compiler tries its best no to lose
* any dependency. Therefore, we do a last-time effort to get the origin of the symbol
* by inspecting the classpath manually.
*
* UPDATE: This can also happen without compiler bugs if the symbol is simply uninitialized.
* Example, `class Client { def foo = Server.foo }`. When compiling client, the type `Foo` returned
* by `Server.foo` does not need to be initialized as we do not select from it or check its
* conformance to another type.
*
* Initializing `targetSymbol` before calling `assosicatedFile` would work but is problematic
* see zinc/zinc#949
*
* Perhaps consider this?
* val file = targetSymbol.associatedFile match {
* case NoAbstractFile => sym.rawInfo match {
* case cfl: global.loaders.ClassfileLoader =>
* val f = cfl.associatedFile(sym) // Gets the file from the loader
* if (f.exists) f else NoAbstractFile
* case f => f
* }
* }
*
* Or the status quo might just be perfectly fine -- if compilation doesn't need to force `Foo`,
* then there isn't a real dependency.
*/
val fqn = fullName(targetSymbol, '.', targetSymbol.moduleSuffix, false)
global.findAssociatedFile(fqn) match {
Expand Down Expand Up @@ -291,9 +312,12 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
assert(fromClass.isClass, Feedback.expectedClassSymbol(fromClass))
val depClass = enclOrModuleClass(dep)
val dependency = ClassDependency(fromClass, depClass)
// An anonymous class be the enclosing class of an existential type symbol inferred from refinements,
// prior to https://github.com/scala/scala/pull/10940. Allowing this here leads to a dependency on class name
// that does not exist. Guard against it here to avoid the issue with legacy compiler versions.
if (
!cache.contains(dependency) &&
!depClass.isRefinementClass
!depClass.isAnonOrRefinementClass
) {
process(dependency)
cache.add(dependency)
Expand Down

0 comments on commit e2f5ea1

Please sign in to comment.