diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index 3fb7a66dc89e..fe5c8d061c78 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -306,6 +306,13 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT } } + private def addInheritanceDependencies(tree: Closure)(using Context): Unit = + // If the tpt is empty, this is a non-SAM lambda, so no need to register + // an inheritance relationship. + if !tree.tpt.isEmpty then + val from = resolveDependencySource + _dependencies += ClassDependency(from, tree.tpt.tpe.classSymbol, LocalDependencyByInheritance) + private def addInheritanceDependencies(tree: Template)(using Context): Unit = if (tree.parents.nonEmpty) { val depContext = depContextOf(tree.symbol.owner) @@ -369,6 +376,8 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT case ref: RefTree => addMemberRefDependency(ref.symbol) addTypeDependency(ref.tpe) + case t: Closure => + addInheritanceDependencies(t) case t: Template => addInheritanceDependencies(t) case _ => diff --git a/sbt-test/source-dependencies/sam/A.scala b/sbt-test/source-dependencies/sam/A.scala new file mode 100644 index 000000000000..eb870b8332b6 --- /dev/null +++ b/sbt-test/source-dependencies/sam/A.scala @@ -0,0 +1,3 @@ +trait A { + def foo(): Int +} diff --git a/sbt-test/source-dependencies/sam/B.scala b/sbt-test/source-dependencies/sam/B.scala new file mode 100644 index 000000000000..87dfb28cdb33 --- /dev/null +++ b/sbt-test/source-dependencies/sam/B.scala @@ -0,0 +1,2 @@ +class B: + val f: A = () => 1 diff --git a/sbt-test/source-dependencies/sam/build.sbt b/sbt-test/source-dependencies/sam/build.sbt new file mode 100644 index 000000000000..63e314982c41 --- /dev/null +++ b/sbt-test/source-dependencies/sam/build.sbt @@ -0,0 +1 @@ +scalaVersion := sys.props("plugin.scalaVersion") diff --git a/sbt-test/source-dependencies/sam/changes/A.scala b/sbt-test/source-dependencies/sam/changes/A.scala new file mode 100644 index 000000000000..e9b339f2d1a4 --- /dev/null +++ b/sbt-test/source-dependencies/sam/changes/A.scala @@ -0,0 +1,3 @@ +trait A { + def foo(): String +} diff --git a/sbt-test/source-dependencies/sam/test b/sbt-test/source-dependencies/sam/test new file mode 100644 index 000000000000..3c4c9a0f001b --- /dev/null +++ b/sbt-test/source-dependencies/sam/test @@ -0,0 +1,7 @@ +> compile + +# change the SAM type +$ copy-file changes/A.scala A.scala + +# Both A.scala and B.scala should be recompiled, producing a compile error +-> compile