diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-04-07 14:08:14 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-04-08 16:24:12 +0200 |
commit | d43f5ce5aa10e39ad05a385c31fc7178eba997c1 (patch) | |
tree | 2bb767924d2c9adb7811a970201df976de2e704d /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | c57c4f8c6227cff8ff9c1392428f97f036a34f2c (diff) | |
download | scala-d43f5ce5aa10e39ad05a385c31fc7178eba997c1.tar.gz scala-d43f5ce5aa10e39ad05a385c31fc7178eba997c1.tar.bz2 scala-d43f5ce5aa10e39ad05a385c31fc7178eba997c1.zip |
SI-7335 Mandate that parents of Predef must be defined in Predef.scala
This avoids thorny issues of cyclic references and/or missing symbol errors
due to the way Predef is completed earlier than user classes, and due to the
addition of `import Predef._` to LowPriorityImplicits.scala. More details in
Lukas's comments in [2].
How did we bootstrap originally? Manually ordering source files,
either in the Ant Build [1], or later in Global [2]. But neither mechanism
remains in place (due, I suppose, to the difficulty in defending them
with a test case.) The reordering in Global was removed in [3].
After the change, we can compile the standard library without the
results of a prior compilation run on the classpath.
rm -rf target/locker/library/classes/scala && export LIB=build/pack/lib; java -Xmx1G -cp $LIB/scala-library.jar:$LIB/scala-reflect.jar:$LIB/scala-compiler.jar:$LIB/forkjoin.jar scala.tools.nsc.Main @args.txt
src/library/scala/SerialVersionUID.scala:15: warning: Implementation restriction: subclassing Classfile does not
make your annotation visible at runtime. If that is what
you want, you must write the annotation class in Java.
class SerialVersionUID(value: Long) extends scala.annotation.ClassfileAnnotation
^
warning: there were 75 deprecation warning(s); re-run with -deprecation for details
warning: there were 1 unchecked warning(s); re-run with -unchecked for details
warning: there were 5 feature warning(s); re-run with -feature for details
four warnings found
Where @args.txt contains:
-classpath
lib/forkjoin.jar:target/locker/library/classes
-sourcepath
src/library
-d
target/locker/library/classes
src/library/scala/Function3.scala
src/library/scala/Console.scala
<more of src/library/**, unsorted>
This change will break scala-virtualized, which will need to move
the contents of StandardEmbeddings.scala into Predef.scala.
[1] https://github.com/scala/scala/commit/c5441dc
[2] https://github.com/scala/scala/commit/e72f0c7
[3] https://github.com/scala/scala/pull/968
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 0be7192471..be59b4e86b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1856,6 +1856,9 @@ trait Typers extends Adaptations with Tags { } val impl2 = finishMethodSynthesis(impl1, clazz, context) + if (mdef.symbol == PredefModule) + ensurePredefParentsAreInSameSourceFile(impl2) + // SI-5954. On second compile of a companion class contained in a package object we end up // with some confusion of names which leads to having two symbols with the same name in the // same owner. Until that can be straightened out we will warn on companion objects in package @@ -1884,6 +1887,12 @@ trait Typers extends Adaptations with Tags { treeCopy.ModuleDef(mdef, typedMods, mdef.name, impl2) setType NoType } + + private def ensurePredefParentsAreInSameSourceFile(template: Template) = { + val parentSyms = template.parents map (_.symbol) filterNot (_ == AnyRefClass) + if (parentSyms exists (_.associatedFile != PredefModule.associatedFile)) + unit.error(template.pos, s"All parents of Predef must be defined in ${PredefModule.associatedFile}.") + } /** In order to override this in the TreeCheckers Typer so synthetics aren't re-added * all the time, it is exposed here the module/class typing methods go through it. * ...but it turns out it's also the ideal spot for namer/typer coordination for |