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

Regression in presentation compiler: imported symbol not found #9283

Closed
scabug opened this issue Apr 28, 2015 · 1 comment
Closed

Regression in presentation compiler: imported symbol not found #9283

scabug opened this issue Apr 28, 2015 · 1 comment

Comments

@scabug
Copy link

scabug commented Apr 28, 2015

Presentation compiler sometimes does not see imported symbols. For example, when I load following two files into the presentation compiler:

// Prestest.scala
package prestest

object Prestest {
  trait Root {
    def meth = 5
  }
}
// ops.scala
package com.whatever

//import prestest.Prestest.Root

object Utils {
  import prestest.Prestest.Root

  implicit class rootOps(root: Root) {
    def implicitMethod: Int = 42
  }
}

I get the following error when typechecking the second file:

ops.scala:10: error: not found: type Root
  implicit class rootOps(root: Root) {
                               ^

The problem disappears when I move the import statement outside of Utils object.

I did a git-bisect and found out that the regression was introduced in 7664e25eed8ae4547f1cfd774b62a7b6a4baf8b5 (fix for #8941).

Here's a full source of test case that I was running:

import scala.reflect.internal.util.BatchSourceFile
import scala.tools.nsc.{interactive, Settings}
import scala.tools.nsc.reporters.ConsoleReporter

object Test {

  def main(args: Array[String]) {
    val settings = new Settings
    settings.usejavacp.value = true
    val reporter = new ConsoleReporter(settings)

    val iglobal = new interactive.Global(settings, reporter)
    import iglobal._

    def getOrThrow[T](resp: Response[T]) = resp.get match {
      case Left(res) => res
      case Right(t) => throw t
    }

    def load(sourceFile: BatchSourceFile) = {
      val resp = new Response[Tree]
      askLoadedTyped(sourceFile, resp)
      getOrThrow(resp)
    }

    val prestestSrc = new BatchSourceFile("Prestest.scala",
      """
        |package prestest
        |
        |object Prestest {
        |  trait Root {
        |    def meth = 5
        |  }
        |}
        |
      """.stripMargin
    )

    load(prestestSrc)

    val opsSrc = new BatchSourceFile("ops.scala",
      """
        |package com.whatever
        |
        |//import prestest.Prestest.Root
        |
        |object Utils {
        |
        |  import prestest.Prestest.Root
        |
        |  implicit class rootOps(root: Root) {
        |    def implicitMethod: Int = 42
        |  }
        |
        |}
      """.stripMargin)

    load(opsSrc)

    if(reporter.hasErrors) {
      throw new Exception("There were errors")
    }
  }

}
@scabug
Copy link
Author

scabug commented Apr 28, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9283?orig=1
Reporter: @ghik
Affected Versions: 2.11.5, 2.11.6
See #8941

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

No branches or pull requests

2 participants