Fix SOE with macros in dependencies extraction

In some cases, expanded macros report that their original tree and
its expansion are the same, thus creating a cyclic chain. This chain
may then produce a SOE during dependencies or used names extraction.

This kind of problem was already reported in sbt/sbt#1237 and
sbt/sbt#1408. Unfortunately, the fix that was applied to the
dependencies extraction part was not sufficient.

Mark test 'source-dependencies/macro' as passing

Fixes #1544
This commit is contained in:
Martin Duhem 2014-09-01 10:07:23 +02:00
parent 68602278d5
commit 8542c9b31a
2 changed files with 19 additions and 15 deletions

View File

@ -102,6 +102,16 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile {
}
private class ExtractDependenciesByMemberRefTraverser extends ExtractDependenciesTraverser {
/*
* Some macros appear to contain themselves as original tree.
* We must check that we don't inspect the same tree over and over.
* See https://issues.scala-lang.org/browse/SI-8486
* https://github.com/sbt/sbt/issues/1237
* https://github.com/sbt/sbt/issues/1544
*/
private val inspectedOriginalTrees = collection.mutable.Set.empty[Tree]
override def traverse(tree: Tree): Unit = {
tree match {
case Import(expr, selectors) =>
@ -136,13 +146,7 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile {
deps.foreach(addDependency)
case Template(parents, self, body) =>
traverseTrees(body)
/*
* Some macros appear to contain themselves as original tree
* In this case, we don't need to inspect the original tree because
* we already inspected its expansion, which is equal.
* See https://issues.scala-lang.org/browse/SI-8486
*/
case MacroExpansionOf(original) if original != tree =>
case MacroExpansionOf(original) if inspectedOriginalTrees.add(original) =>
this.traverse(original)
case other => ()
}