Skip to content

java.util.NoSuchElementException: None.get when using Compiler.newRun() during ContextBase.initialize() #12998

@GavinRay97

Description

@GavinRay97

Heya, sorry for the troubles, but I've been spending a good chunk of time attempting to PR support for Scala 3 to Quarkus as a newbie to both the JVM and to Scala.

I think the feature is pretty much finished, but on the actual invocation of the compiler I've hit a roadblock and I'd be grateful for any advice or direction -- googling doesn't seem to turn up much. This is the error that I get:

java.util.NoSuchElementException: None.get
	at scala.None$.get(Option.scala:627)
	at scala.None$.get(Option.scala:626)
	at dotty.tools.dotc.core.Definitions.add$1(Definitions.scala:1776)
	at dotty.tools.dotc.core.Definitions.addSyntheticSymbolsComments(Definitions.scala:1779)
	at dotty.tools.dotc.core.Definitions.init(Definitions.scala:1772)
	at dotty.tools.dotc.core.Contexts$ContextBase.initialize(Contexts.scala:855)
	at dotty.tools.dotc.core.Contexts$Context.initialize(Contexts.scala:560)
	at dotty.tools.dotc.Run.rootContext(Run.scala:69)
	at dotty.tools.dotc.Run.<init>(Run.scala:89)
	at dotty.tools.dotc.Compiler.newRun(Compiler.scala:158)
	at org.acme.quarkus.scala.three.deployment.Scala3CompilationProvider.compile(Scala3CompilationProvider.scala:70)
	at io.quarkus.deployment.dev.QuarkusCompiler.compile(QuarkusCompiler.java:191)

And the code for it this:

class Scala3CompilationProvider extends CompilationProvider:
  override def handledExtensions: util.Set[String]  = Collections.singleton(".scala")
  override def handledSourcePaths: util.Set[String] = super.handledSourcePaths

  override def compile(files: util.Set[File], context: CompilationProvider.Context): Unit =
    val log = Scala3CompilationProvider.log

    val callback = CustomCompilerCallback()
    val classPath =
      context.getClasspath.stream
        .map(_.getAbsolutePath)
        .collect(Collectors.joining(File.pathSeparator))

    // https://github.com/lampepfl/dotty/blob/b7d2a122555a6aa44cc7590852a80f12512c535e/compiler/test/dotty/tools/DottyTest.scala
    // https://github.com/scalameta/mdoc/blob/b9437b7d3d0c9e04a9c8e86de96f10db0be5de91/mdoc/src/main/scala-3/mdoc/internal/markdown/MarkdownCompiler.scala
    val base = new ContextBase {}
    import base.settings._
    val ctx = base.initialCtx.fresh
    ctx.setSetting(ctx.settings.classpath, classPath)
    ctx.setSetting(ctx.settings.outputDir, new PlainDirectory(Directory(context.getOutputDirectory.getAbsolutePath)))
    base.initialize()(using ctx)

    val dottyFiles: List[AbstractFile] = files.stream().map(it =>
      new PlainFile(dotty.tools.io.Path(it.toPath))
    ).collect(Collectors.toList)

    log.info("dottyFiles")
    log.info(dottyFiles)

    log.info("dottyFiles.iterator().asScala.toList")
    log.info(dottyFiles.iterator().asScala.toList)

    val compiler = new Compiler
    val run      = compiler.newRun(using ctx)
    run.compile(dottyFiles.iterator().asScala.toList)

From the logs, I can see that it picks up on the 1 changed file and everything looks okay.
I'm not really sure what is going on here 🤔

2021-07-01 22:19:39,878 INFO dottyFiles
2021-07-01 22:19:39,878 INFO [C:\Users\rayga\Projects\tmp\quarkus-scala-three-container\quarkus-scala-three-app\src\main\scala\org\acme\GreetingResource.scala]
2021-07-01 22:19:39,878 INFO dottyFiles.iterator().asScala.toList
2021-07-01 22:19:39,880 INFO List(C:\Users\rayga\Projects\tmp\quarkus-scala-three-container\quarkus-scala-three-app\src\main\scala\org\acme\GreetingResource.scala)

For reference in case it's useful, the current code that handles compiling Scala 2 is:

    public void compile(Set<File> files, Context context) {
        Settings settings = new Settings();
        context.getClasspath().stream()
                .map(File::getAbsolutePath)
                .forEach(f -> settings.classpath().append(f));
        settings.outputDirs().add(context.getSourceDirectory().getAbsolutePath(),
                context.getOutputDirectory().getAbsolutePath());
        try (Global g = new Global(settings)) {
            Global.Run run = g.new Run();
            Set<String> fileSet = files.stream()
                    .map(File::getAbsolutePath)
                    .collect(Collectors.toSet());
            run.compile(JavaConverters.asScalaSet(fileSet).toList());
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions