Skip to content

Commit 9564900

Browse files
committed
Fix under-compilation when the method type in a SAM changes
A lambda that implements a SAM type desugars (either at compile-time or runtime via invokedynamic) into a class that extends the SAM type, therefore we need to register an inheritance relationship to get the proper invalidation logic. Fixes sbt/zinc#830.
1 parent 9a9834e commit 9564900

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
306306
}
307307
}
308308

309+
private def addInheritanceDependencies(tree: Closure)(using Context): Unit =
310+
val from = resolveDependencySource
311+
_dependencies += ClassDependency(from, tree.tpt.tpe.classSymbol, LocalDependencyByInheritance)
312+
309313
private def addInheritanceDependencies(tree: Template)(using Context): Unit =
310314
if (tree.parents.nonEmpty) {
311315
val depContext = depContextOf(tree.symbol.owner)
@@ -369,6 +373,8 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
369373
case ref: RefTree =>
370374
addMemberRefDependency(ref.symbol)
371375
addTypeDependency(ref.tpe)
376+
case t: Closure =>
377+
addInheritanceDependencies(t)
372378
case t: Template =>
373379
addInheritanceDependencies(t)
374380
case _ =>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait A {
2+
def foo(): Int
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class B:
2+
val f: A = () => 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scalaVersion := sys.props("plugin.scalaVersion")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait A {
2+
def foo(): String
3+
}

sbt-test/source-dependencies/sam/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> compile
2+
3+
# change the SAM type
4+
$ copy-file changes/A.scala A.scala
5+
6+
# Both A.scala and B.scala should be recompiled, producing a compile error
7+
-> compile

0 commit comments

Comments
 (0)