Skip to content
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

Reading Scala 3 class files from Scala 2.13 Ammonite.Main().run() #1327

Open
fabianhjr opened this issue Feb 22, 2023 · 3 comments
Open

Reading Scala 3 class files from Scala 2.13 Ammonite.Main().run() #1327

fabianhjr opened this issue Feb 22, 2023 · 3 comments

Comments

@fabianhjr
Copy link
Contributor

fabianhjr commented Feb 22, 2023

From: https://docs.scala-lang.org/scala3/guides/migration/compatibility-classpath.html

A Scala 2.13 module can depend on a Scala 3 artifact

By enabling the TASTy reader with -Ytasty-reader, a Scala 2.13 module can depend on a Scala 3 artifact.

image

Minimum example: https://github.com/fabianhjr/ammonite-scala3-issue

Use case is debug repl

Attempted Workarounds

error while loading [Thing], Missing dependency 'Add -Ytasty-reader to scalac options to parse the TASTy in [Path]

Tried:

ammonite.Main(
  predefCode = "interp.configureCompiler(_.settings.processArguments(List(\"-Ytasty-reader\"), true))
)
ammonit.Main(
  predefFile = [Path to predef.sc with the above]
)

and

           ammonite
              .Main(
                compilerBuilder = new ICompilerBuilder {
                  override def create(
                      initialClassPath: Seq[URL],
                      classPath: Seq[URL],
                      dynamicClassPath: Seq[(String, Array[Byte])],
                      evalClassLoader: ClassLoader,
                      pluginClassLoader: ClassLoader,
                      reporter: Option[ICompilerBuilder.Message => Unit],
                      settings: Seq[String],
                      classPathWhiteList: Set[Seq[String]],
                      lineNumberModifier: Boolean
                  ): ICompiler =
                    CompilerBuilder.create(
                      initialClassPath,
                      classPath,
                      dynamicClassPath,
                      evalClassLoader,
                      pluginClassLoader,
                      reporter,
                      settings ++ Seq("-Ytasty-reader"),
                      classPathWhiteList,
                      lineNumberModifier
                    )

                  override def newManager(
                      rtCacheDir: Option[Path],
                      headFrame: => Frame,
                      dependencyCompleter: => Option[String => (Int, Seq[String])],
                      whiteList: Set[Seq[String]],
                      initialClassLoader: ClassLoader
                  ): CompilerLifecycleManager = CompilerBuilder
                    .newManager(rtCacheDir, headFrame, dependencyCompleter, whiteList, initialClassLoader)

                  override def scalaVersion: String = CompilerBuilder.scalaVersion
                }
@fabianhjr fabianhjr changed the title Reading Scala 3 .class files from Scala 2.13 Ammonite.Main().run() Reading Scala 3 class files from Scala 2.13 Ammonite.Main().run() Feb 22, 2023
@fabianhjr
Copy link
Contributor Author

fabianhjr commented Feb 22, 2023

Looking at the source of ammonite.Main.run seems like the replArgs get evaluated before other things.

  def run(replArgs: Bind[_]*): (Res[Any], Seq[(Watchable, Long)]) = {


    instantiateRepl(replArgs.toIndexedSeq) match{
      case Left(missingPredefInfo) => missingPredefInfo
      case Right(repl) =>

So I am a bit confused about how to add this flags to ammonite Main.run on the debug and instinctively I think this function might require an extra argument for the flags/settings. (Tough would appreciate maintainer input on whether such a change would be desired, can work on a fix on my spare time)

@fabianhjr
Copy link
Contributor Author

Uploaded a minimum example to: https://github.com/fabianhjr/ammonite-scala3-issue

@ivanmoreau
Copy link

Hi Fabian! I think you MWE is wrong, as it does not represent the actual error that you are describing in your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants