-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with macros and in-memory (virtual) source files #13010
Comments
To be clear, the issue is not immediately reproducible with MUnit and Scala 2. But the possibility of the same issue exists. Let's see how the discussion in the Scala 3 repo unfolds. |
The disclaimer was always:
Demonstrate that sourcecode and munit for Scala 2 both use //> using scala 2.13
//> using options -Wnonunit-statement -Xlint -Xsource:3-cross
//> using dep com.lihaoyi::sourcecode:0.4.2
//> using dep com.lihaoyi::os-lib:0.10.2
//> using dep org.scalameta::munit:1.0.0
//> using dep org.scala-lang:scala-compiler:2.13.14
import java.io.{InputStreamReader, PrintStream, StringWriter}
import scala.reflect.io.VirtualFile
import scala.sys.process.*
import scala.tools.nsc.{Global, Settings}
import scala.util.Using
import scala.util.chaining.*
object Test extends App {
val tmp = os.temp.dir()
val s = new Settings().tap(_.processArgumentString(s"-usejavacp -d $tmp -Xlint"))
val g = new Global(s)
val f = new VirtualFile(name="vf", path="/p/vf")
def code =
s"""
|object Test extends App {
| println {
| s"hello, new world at $${sourcecode.File()}"
| }
| println(new LocationTestSuite().munitTests().map(_.body()))
|}
|
|class LocationTestSuite extends munit.FunSuite {
| test("location") {
| assert(true)
| }
|}
""".stripMargin
Using.resource(new PrintStream(f.output))(_.print(code))
val txt = Using.resource(new InputStreamReader(f.input)) { reader =>
val w = new StringWriter
reader.transferTo(w)
w.toString
}
assert(txt == code)
println {
s"hello, world at ${sourcecode.File()}"
}
val r = new g.Run
r.compileFiles(List(f))
assert(!g.reporter.hasErrors)
val cp = g.classPath.asClassPathStrings.filter(_.endsWith(".jar")).mkString(":") + s":$tmp"
println {
Seq("scala", "-cp", cp, "Test").!!
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I opened the same ticket in the Scala 3 repo.
scala/scala3#20591
The issue affects all versions of Scala, and the implementation details are relevant to both Scala 2 and Scala 3, as the sources in question have been transferred from Scala 2 to Scala 3 over the years.
Thanks in advance.
The text was updated successfully, but these errors were encountered: