From 8fe0f04581be2c0d03dff0d8dabffdb00041f8c9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 31 Aug 2017 17:39:59 +0200 Subject: [PATCH 1/4] Fix #2395: Check if the scala or dotty libraries are missing --- .../dotty/tools/dotc/MissingCoreLibraryException.scala | 9 +++++++++ compiler/src/dotty/tools/dotc/core/Definitions.scala | 2 +- compiler/src/dotty/tools/dotc/core/Denotations.scala | 5 ++++- compiler/src/dotty/tools/dotc/core/StdNames.scala | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala diff --git a/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala b/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala new file mode 100644 index 000000000000..ae20d81226c9 --- /dev/null +++ b/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala @@ -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 +) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 561ee6a00746..ce2ce247060c 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 75d1261c3d44..85f64f144cdf 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1199,7 +1199,10 @@ object Denotations { 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 (owner.symbol == defn.RootClass && (selector == nme.scala_ || selector == nme.scalaShadowing)) + throw new MissingCoreLibraryException(selector.toString) + else MissingRef(owner, selector) } } else owner diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index 312ebcf1b5f7..b4fd1efa745a 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -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" From 3e5009d95b89a20749f92fd9998466b06ded87db Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 31 Aug 2017 18:21:58 +0200 Subject: [PATCH 2/4] Add test for #2395 --- .../tools/dotc/MissingCoreLibTests.scala | 34 +++++++++++++++++++ .../tools/vulpix/TestConfiguration.scala | 8 +++-- tests/neg/nolib/Foo.scala | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala create mode 100644 tests/neg/nolib/Foo.scala diff --git a/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala b/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala new file mode 100644 index 000000000000..593121c6b0d4 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala @@ -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() +} diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 44dabbabc93f..816221a0a13d 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -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]) = { + val paths = deps map { p => val file = new java.io.File(p) assert( file.exists, @@ -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" diff --git a/tests/neg/nolib/Foo.scala b/tests/neg/nolib/Foo.scala new file mode 100644 index 000000000000..ef4e4e70d01d --- /dev/null +++ b/tests/neg/nolib/Foo.scala @@ -0,0 +1,2 @@ +// nopos-error +class Foo From 4d6c29fc89f5641acfd9aec7620e070ad5a10b58 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Sep 2017 11:08:57 +0200 Subject: [PATCH 3/4] Add documentation --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 10 ++++++++-- .../test/dotty/tools/vulpix/TestConfiguration.scala | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 85f64f144cdf..4724e68f2cb7 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1192,6 +1192,13 @@ 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 @@ -1200,8 +1207,7 @@ object Denotations { if (generateStubs) missingHook(owner.symbol.moduleClass, selector) else NoSymbol if (alt.exists) alt.denot - else if (owner.symbol == defn.RootClass && (selector == nme.scala_ || selector == nme.scalaShadowing)) - throw new MissingCoreLibraryException(selector.toString) + else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString) else MissingRef(owner, selector) } } diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 816221a0a13d..06022833dbb8 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -25,7 +25,7 @@ object TestConfiguration { val classPath = mkClassPath(Jars.dottyTestDeps) - def mkClassPath(deps: List[String]) = { + def mkClassPath(deps: List[String]): Array[String] = { val paths = deps map { p => val file = new java.io.File(p) assert( From 025885905d178607f8629a2d0deedd0df8b5fcf9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Sep 2017 19:21:32 +0200 Subject: [PATCH 4/4] Small format fix --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 4724e68f2cb7..14a93191e4a6 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1194,10 +1194,10 @@ object Denotations { 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)