Skip to content

Commit e031348

Browse files
committed
Add failing test for #11861
1 parent 7627583 commit e031348

File tree

10 files changed

+71
-0
lines changed

10 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A {
2+
inline def callInline: Int = inlinedInt
3+
4+
inline def inlinedInt: Int = 23
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class B {
2+
def main(args: Array[String]): Unit = {
3+
assert(A.callInline == C.expected)
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object C {
2+
def expected: Int = 23
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sbt.internal.inc.Analysis
2+
import complete.DefaultParsers._
3+
4+
// Reset compiler iterations, necessary because tests run in batch mode
5+
val recordPreviousIterations = taskKey[Unit]("Record previous iterations.")
6+
recordPreviousIterations := {
7+
val log = streams.value.log
8+
CompileState.previousIterations = {
9+
val previousAnalysis = (previousCompile in Compile).value.analysis.asScala
10+
previousAnalysis match {
11+
case None =>
12+
log.info("No previous analysis detected")
13+
0
14+
case Some(a: Analysis) => a.compilations.allCompilations.size
15+
}
16+
}
17+
}
18+
19+
val checkIterations = inputKey[Unit]("Verifies the accumulated number of iterations of incremental compilation.")
20+
21+
checkIterations := {
22+
val expected: Int = (Space ~> NatBasic).parsed
23+
val actual: Int = ((compile in Compile).value match { case a: Analysis => a.compilations.allCompilations.size }) - CompileState.previousIterations
24+
assert(expected == actual, s"Expected $expected compilations, got $actual")
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object A {
2+
inline def callInline: Int = inlinedInt
3+
4+
inline def inlinedInt: Int = 47
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object C {
2+
def expected: Int = 47
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
logLevel := Level.Debug
2+
incOptions in ThisBuild ~= { _.withApiDebug(true) }
3+
incOptions in ThisBuild ~= { _.withRelationsDebug(true) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is necessary because tests are run in batch mode
2+
object CompileState {
3+
@volatile var previousIterations: Int = -1
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion")
10+
)
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
> compile
2+
> recordPreviousIterations
3+
# Force recompilation of B because A.inlinedInt, called by A.callInline, has changed
4+
$ copy-file changes/A1.scala A.scala
5+
> compile
6+
# 1 to recompile A, then 1 more to recompile B due to A.inlinedInt change
7+
> checkIterations 2

0 commit comments

Comments
 (0)