Skip to content

Commit 15a2a6c

Browse files
committed
Support zinc invalidation for type arguments of macro calls
1 parent c4c48e3 commit 15a2a6c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,30 @@ private class ExtractDependenciesCollector(rec: DependencyRecorder) extends tpd.
165165
rec.addClassDependency(parent.tpe.classSymbol, depContext)
166166
}
167167

168+
// Only reference DependencyByMacroExpansion if it an be found on the classpath,
169+
// as it was added later to the zinc.apiinfo DependencyContext enum
170+
// e.g. pre 1.10.x sbt would throw java.lang.NoSuchFieldError errors here
171+
lazy val allowsDependencyByMacroExpansion =
172+
classOf[DependencyContext].getFields().exists(_.getName() == "DependencyByMacroExpansion")
173+
174+
private def addMacroDependency(sym: Symbol)(using Context): Unit =
175+
if (allowsDependencyByMacroExpansion) {
176+
if (!ignoreDependency(sym)) {
177+
if (!sym.is(Package)) {
178+
val enclOrModuleClass = if (sym.is(ModuleVal)) sym.moduleClass else sym.enclosingClass
179+
assert(enclOrModuleClass.isClass, s"$enclOrModuleClass, $sym")
180+
181+
rec.addClassDependency(enclOrModuleClass, DependencyByMacroExpansion)
182+
}
183+
}
184+
}
185+
186+
private def addMacroDependency(trees: List[Tree])(using Context): Unit =
187+
val traverser = new TypeDependencyTraverser {
188+
def addDependency(symbol: Symbol) = addMacroDependency(symbol)
189+
}
190+
trees.foreach(tree => traverser.traverse(tree.tpe))
191+
168192
private def depContextOf(cls: Symbol)(using Context): DependencyContext =
169193
if cls.isLocal then LocalDependencyByInheritance
170194
else DependencyByInheritance
@@ -226,6 +250,11 @@ private class ExtractDependenciesCollector(rec: DependencyRecorder) extends tpd.
226250
case _ =>
227251
}
228252

253+
tree match
254+
case TypeApply(fun, args) if fun.symbol.is(Inline) =>
255+
addMacroDependency(args)
256+
case _ =>
257+
229258
tree match {
230259
case tree: Inlined if !tree.inlinedFromOuterScope =>
231260
// The inlined call is normally ignored by TreeTraverser but we need to

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ object Build {
13541354
Compile / scalacOptions ++= Seq("--java-output-version", Versions.minimumJVMVersion),
13551355
// Add all the project's external dependencies
13561356
libraryDependencies ++= Seq(
1357-
("org.scala-sbt" %% "zinc-apiinfo" % "1.8.0" % Test).cross(CrossVersion.for3Use2_13),
1357+
("org.scala-sbt" %% "zinc-apiinfo" % "1.10.8" % Test).cross(CrossVersion.for3Use2_13),
13581358
"com.github.sbt" % "junit-interface" % "0.13.3" % Test,
13591359
),
13601360
// Exclude the transitive dependencies from `zinc-apiinfo` that causes issues at the moment

0 commit comments

Comments
 (0)