Skip to content

Fix #2395: Check if the scala or dotty libraries are missing #3045

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

Merged
merged 4 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dotty.tools.dotc

import dotty.tools.FatalError

class MissingCoreLibraryException(rootPackage: String) extends FatalError(
s"""Could not find package $rootPackage from compiler core libraries.
|Make sure the compiler core libraries are on the classpath.
""".stripMargin
)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Definitions {
* in `scalaShadowing` so they don't clash with the same-named `scala`
* members at runtime.
*/
lazy val ScalaShadowingPackageVal = ctx.requiredPackage("scalaShadowing")
lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing)
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass

/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)
Expand Down
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1192,14 +1192,23 @@ object Denotations {
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(implicit ctx: Context): Denotation = {
def select(prefix: Denotation, selector: Name): Denotation = {
val owner = prefix.disambiguate(_.info.isParameterless)
def isPackageFromCoreLibMissing: Boolean = {
owner.symbol == defn.RootClass &&
(
selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
)
}
if (owner.exists) {
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
if (result.exists) result
else {
val alt =
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
else NoSymbol
if (alt.exists) alt.denot else MissingRef(owner, selector)
if (alt.exists) alt.denot
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
else MissingRef(owner, selector)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter could you review the isPackageFromCoreLibMissing condition in this file. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

}
}
else owner
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ object StdNames {
val runtimeMirror: N = "runtimeMirror"
val sameElements: N = "sameElements"
val scala_ : N = "scala"
val scalaShadowing : N = "scalaShadowing"
val selectDynamic: N = "selectDynamic"
val selectDynamicMethod: N = "selectDynamicMethod"
val selectOverloadedMethod: N = "selectOverloadedMethod"
Expand Down
34 changes: 34 additions & 0 deletions compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dotty
package tools
package dotc

import org.junit.{ Test, AfterClass }

import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }

import scala.concurrent.duration._

class MissingCoreLibTests extends ParallelTesting {
import MissingCoreLibTests._
import TestConfiguration._

// Test suite configuration --------------------------------------------------

def maxDuration = 30.seconds
def numberOfSlaves = 5
def safeMode = Properties.testsSafeMode
def isInteractive = SummaryReport.isInteractive
def testFilter = Properties.testsFilter

@Test def missingDottyLib: Unit = {
val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib
val options = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
compileFile("../tests/neg/nolib/Foo.scala", options).checkExpectedErrors()
}

}

object MissingCoreLibTests {
implicit val summaryReport: SummaryReporting = new SummaryReport
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
}
8 changes: 5 additions & 3 deletions compiler/test/dotty/tools/vulpix/TestConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ object TestConfiguration {
"-Yforce-sbt-phases"
)

val classPath = {
val paths = Jars.dottyTestDeps map { p =>
val classPath = mkClassPath(Jars.dottyTestDeps)

def mkClassPath(deps: List[String]): Array[String] = {
val paths = deps map { p =>
val file = new java.io.File(p)
assert(
file.exists,
Expand All @@ -50,7 +52,7 @@ object TestConfiguration {
Array("-classpath", paths)
}

private val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,erasure,mixin,getClass,restoreScopes,labelDef")
val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,erasure,mixin,getClass,restoreScopes,labelDef")

val defaultUnoptimised = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
val defaultOptimised = defaultUnoptimised :+ "-optimise"
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/nolib/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// nopos-error
class Foo