Skip to content

Commit 717904b

Browse files
authored
Merge pull request #3045 from dotty-staging/fix-#2395
Fix #2395: Check if the scala or dotty libraries are missing
2 parents 8f15b2a + 0258859 commit 717904b

File tree

7 files changed

+62
-5
lines changed

7 files changed

+62
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.tools.dotc
2+
3+
import dotty.tools.FatalError
4+
5+
class MissingCoreLibraryException(rootPackage: String) extends FatalError(
6+
s"""Could not find package $rootPackage from compiler core libraries.
7+
|Make sure the compiler core libraries are on the classpath.
8+
""".stripMargin
9+
)

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Definitions {
212212
* in `scalaShadowing` so they don't clash with the same-named `scala`
213213
* members at runtime.
214214
*/
215-
lazy val ScalaShadowingPackageVal = ctx.requiredPackage("scalaShadowing")
215+
lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing)
216216
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass
217217

218218
/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,14 +1192,23 @@ object Denotations {
11921192
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(implicit ctx: Context): Denotation = {
11931193
def select(prefix: Denotation, selector: Name): Denotation = {
11941194
val owner = prefix.disambiguate(_.info.isParameterless)
1195+
def isPackageFromCoreLibMissing: Boolean = {
1196+
owner.symbol == defn.RootClass &&
1197+
(
1198+
selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing
1199+
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
1200+
)
1201+
}
11951202
if (owner.exists) {
11961203
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
11971204
if (result.exists) result
11981205
else {
11991206
val alt =
12001207
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
12011208
else NoSymbol
1202-
if (alt.exists) alt.denot else MissingRef(owner, selector)
1209+
if (alt.exists) alt.denot
1210+
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
1211+
else MissingRef(owner, selector)
12031212
}
12041213
}
12051214
else owner

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ object StdNames {
491491
val runtimeMirror: N = "runtimeMirror"
492492
val sameElements: N = "sameElements"
493493
val scala_ : N = "scala"
494+
val scalaShadowing : N = "scalaShadowing"
494495
val selectDynamic: N = "selectDynamic"
495496
val selectDynamicMethod: N = "selectDynamicMethod"
496497
val selectOverloadedMethod: N = "selectOverloadedMethod"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty
2+
package tools
3+
package dotc
4+
5+
import org.junit.{ Test, AfterClass }
6+
7+
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
8+
9+
import scala.concurrent.duration._
10+
11+
class MissingCoreLibTests extends ParallelTesting {
12+
import MissingCoreLibTests._
13+
import TestConfiguration._
14+
15+
// Test suite configuration --------------------------------------------------
16+
17+
def maxDuration = 30.seconds
18+
def numberOfSlaves = 5
19+
def safeMode = Properties.testsSafeMode
20+
def isInteractive = SummaryReport.isInteractive
21+
def testFilter = Properties.testsFilter
22+
23+
@Test def missingDottyLib: Unit = {
24+
val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib
25+
val options = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
26+
compileFile("../tests/neg/nolib/Foo.scala", options).checkExpectedErrors()
27+
}
28+
29+
}
30+
31+
object MissingCoreLibTests {
32+
implicit val summaryReport: SummaryReporting = new SummaryReport
33+
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
34+
}

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ object TestConfiguration {
2323
"-Yforce-sbt-phases"
2424
)
2525

26-
val classPath = {
27-
val paths = Jars.dottyTestDeps map { p =>
26+
val classPath = mkClassPath(Jars.dottyTestDeps)
27+
28+
def mkClassPath(deps: List[String]): Array[String] = {
29+
val paths = deps map { p =>
2830
val file = new java.io.File(p)
2931
assert(
3032
file.exists,
@@ -50,7 +52,7 @@ object TestConfiguration {
5052
Array("-classpath", paths)
5153
}
5254

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

5557
val defaultUnoptimised = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
5658
val defaultOptimised = defaultUnoptimised :+ "-optimise"

tests/neg/nolib/Foo.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// nopos-error
2+
class Foo

0 commit comments

Comments
 (0)