Skip to content

Global.askLoadedTyped no longer reports warnings #12308

@tgodzik

Description

@tgodzik

reproduction steps

using Scala 2.12.13 and 2.13.x

  def toTextDocument(
      global: Global,
      code: String,
      filename: String,
      timeout: Long,
      options: List[String]
  ): s.TextDocument = {
    val unit = addCompilationUnit(global, code, filename)
    global.typeCheck(unit)
    // reload seems to be necessary before askLoadedType.
    ask[Unit](r => global.askReload(unit.source :: Nil, r)).get
    val compiledTree =
      ask[compiler.Tree](r => global.askLoadedTyped(unit.source, r))
        .get(timeout)
    val tree = compiledTree match {
      case Some(Left(t)) => t
      case Some(Right(ex)) => throw ex
      case None => throw new IllegalArgumentException("Presentation compiler timed out")
    }
    lazy val semanticdbOps: SemanticdbOps {
      val global: global.type
    } = new SemanticdbOps {
      val global: global.type = compiler
    }
    semanticdbOps.config =
      SemanticdbConfig.parse(options, _ => (), global.reporter, SemanticdbConfig.default)
    import semanticdbOps._
    unit.body = tree
    val document = unit.asInstanceOf[semanticdbOps.global.CompilationUnit].toTextDocument
    document
  }

problem

We use compiler.askLoadedTyped to interactively construct semanticdb file to be used for example in scalafix. When we enable -Ywarn-unused:imports until 2.12.12 it used to report the warnings right away with it. However, this no longer works in 2.12.13 and as it also turns out in 2.13.x also.

I think this might have something to do with the recent -Wconf changes as running global.compileSources does report them (though we don't get a fully typed tree or at least I was unable to obtain it.).

Is there a way to force the warnings to be reported straight away? @lrytz any idea how I can work around it? Basically I need the fully typed tree and warnings reported. I will try to work around it but any help would be appreciated.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions