diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 751973065d0a..e439ebfd60f7 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -304,10 +304,6 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint def process()(using Context) = { - def parseSource()(using Context) = - if (unit.isJava) new JavaParser(unit.source).parse() - else new Parser(unit.source).parse() - def enterTrees()(using Context) = ctx.typer.lateEnter(unit.untpdTree) def typeCheckUnit()(using Context) = @@ -321,7 +317,9 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint if compiling then finalizeActions += (() => typeCheckUnit()(using typerCtx)) else typeCheckUnit()(using typerCtx) - unit.untpdTree = parseSource() + unit.untpdTree = + if (unit.isJava) new JavaParser(unit.source).parse() + else new Parser(unit.source).parse() val namerCtx = // inline body annotations are set in namer, capturing the current context // we need to prepare the context for inlining. diff --git a/project/scripts/bootstrapCmdTests b/project/scripts/bootstrapCmdTests index 9f8956e1d23c..a2ff55243f11 100755 --- a/project/scripts/bootstrapCmdTests +++ b/project/scripts/bootstrapCmdTests @@ -83,3 +83,11 @@ clear_out "$OUT" ./bin/scalac -d "$OUT/out.jar" tests/pos/i12973.scala echo "Bug12973().check" | TERM=dumb ./bin/scala -cp "$OUT/out.jar" > "$tmp" 2>&1 grep -qe "Bug12973 is fixed" "$tmp" + +echo "testing -sourcepath with inlining" +cwd=$(pwd) +java_prop="pack.version.file=$cwd/dist/target/pack/VERSION" +(cd "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline" && "$SBT" "-D$java_prop" ";clean;prepareSources;compile;copyChanges;compile") +rm -rf "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/target" +rm -rf "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/target" +rm -f "$cwd/tests/cmdTest-sbt-tests/sourcepath-with-inline/src/main/scala/a/zz.scala" diff --git a/project/scripts/cmdTestsCommon.inc.sh b/project/scripts/cmdTestsCommon.inc.sh index dc81a3e35b52..587dd3527bd2 100644 --- a/project/scripts/cmdTestsCommon.inc.sh +++ b/project/scripts/cmdTestsCommon.inc.sh @@ -1,6 +1,8 @@ set -eux -SBT="./project/scripts/sbt" # if run on CI +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/../.." + +SBT="$ROOT/project/scripts/sbt" # if run on CI # SBT="sbt" # if run locally SOURCE="tests/pos/HelloWorld.scala" diff --git a/tests/cmdTest-sbt-tests/README.md b/tests/cmdTest-sbt-tests/README.md new file mode 100644 index 000000000000..3738c0861fb1 --- /dev/null +++ b/tests/cmdTest-sbt-tests/README.md @@ -0,0 +1,7 @@ +# Readme + +Do not use this directory for testing sbt projects in general, add a test case to `dotty/sbt-test` + +This directory is for sbt tests that can not be reproduced with sbt scripted tests. + +Adding a test here will reduce the performance of running all tests. diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/build.sbt b/tests/cmdTest-sbt-tests/sourcepath-with-inline/build.sbt new file mode 100644 index 000000000000..4bff160ff55a --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/build.sbt @@ -0,0 +1,17 @@ +import java.util.Properties + +val prepareSources = taskKey[Unit]("Copy changes to the src directory") +val copyChanges = taskKey[Unit]("Copy changes to the src directory") + +val srcDir = settingKey[File]("The directory to copy changes to") +val changesDir = settingKey[File]("The directory to copy changes from") + +srcDir := (ThisBuild / baseDirectory).value / "src" / "main" / "scala" +changesDir := (ThisBuild / baseDirectory).value / "changes" + +prepareSources := IO.copyFile(changesDir.value / "zz.original.scala", srcDir.value / "a" / "zz.scala") +copyChanges := IO.copyFile(changesDir.value / "zz.new.scala", srcDir.value / "a" / "zz.scala") + +(Compile / scalacOptions) ++= Seq( + "-sourcepath", (Compile / sourceDirectories).value.map(_.getAbsolutePath).distinct.mkString(java.io.File.pathSeparator), +) diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.new.scala b/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.new.scala new file mode 100644 index 000000000000..fbf5cf7fb5e0 --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.new.scala @@ -0,0 +1,7 @@ +package a + +object Foo: // note that `Foo` is defined in `zz.scala` + class Local + inline def foo(using Local): Nothing = + ??? + ??? diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.original.scala b/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.original.scala new file mode 100644 index 000000000000..17a7488ccb1a --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/changes/zz.original.scala @@ -0,0 +1,6 @@ +package a + +object Foo: // note that `Foo` is defined in `zz.scala` + class Local + inline def foo(using Local): Nothing = + ??? diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/DottyInjectedPlugin.scala b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/DottyInjectedPlugin.scala new file mode 100644 index 000000000000..1cdccf273e9a --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/DottyInjectedPlugin.scala @@ -0,0 +1,27 @@ +import sbt._ +import Keys._ + +import java.util.Properties +import java.io.File + +object DottyInjectedPlugin extends AutoPlugin { + override def requires = plugins.JvmPlugin + override def trigger = allRequirements + + private val packProperties = settingKey[Properties]("The properties of the dist/pack command") + + override val projectSettings = Seq( + packProperties := { + val prop = new Properties() + IO + .read(new File(sys.props("pack.version.file"))) + .linesIterator + .foreach { line => + val Array(key, value) = line.split(":=") + prop.setProperty(key, value) + } + prop + }, + scalaVersion := packProperties.value.getProperty("version") + ) +} diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties new file mode 100644 index 000000000000..10fd9eee04ac --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.5 diff --git a/tests/cmdTest-sbt-tests/sourcepath-with-inline/src/main/scala/a/Bar.scala b/tests/cmdTest-sbt-tests/sourcepath-with-inline/src/main/scala/a/Bar.scala new file mode 100644 index 000000000000..79af4eb2cebd --- /dev/null +++ b/tests/cmdTest-sbt-tests/sourcepath-with-inline/src/main/scala/a/Bar.scala @@ -0,0 +1,5 @@ +package a + +object Bar: + given Foo.Local() + def Bar = Foo.foo