diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeInfo.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 2 | ||||
-rw-r--r-- | src/library/scala/ScalaObject.scala | 1 |
3 files changed, 16 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala index 3cfb6ccc76..0c056fd1c6 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeInfo.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeInfo.scala @@ -283,6 +283,20 @@ abstract class TreeInfo { false } + /** Compilation unit is the predef object + */ + def isPredefUnit(tree: Tree): Boolean = tree match { + case PackageDef(nme.scala_, List(obj)) => isPredefObj(obj) + case _ => false + } + + private def isPredefObj(tree: Tree): Boolean = tree match { + case ModuleDef(_, nme.Predef, _) => true + case DocDef(_, tree1) => isPredefObj(tree1) + case Annotated(_, tree1) => isPredefObj(tree1) + case _ => false + } + def isAbsTypeDef(tree: Tree) = tree match { case TypeDef(_, _, _, TypeBoundsTree(_, _)) => true case TypeDef(_, _, _, rhs) => rhs.tpe.isInstanceOf[TypeBounds] diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index fc5d2a9e50..1f0750d580 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -44,7 +44,7 @@ trait Contexts { self: Analyzer => imps += JavaLangPackage assert(ScalaPackage ne null, "Scala package is null") imps += ScalaPackage - if (!(settings.nopredefs.value || treeInfo.containsLeadingPredefImport(List(unit.body)))) + if (!(treeInfo.isPredefUnit(unit.body) || treeInfo.containsLeadingPredefImport(List(unit.body)))) imps += PredefModule } imps.toList diff --git a/src/library/scala/ScalaObject.scala b/src/library/scala/ScalaObject.scala index 9979343397..82dc19c9dd 100644 --- a/src/library/scala/ScalaObject.scala +++ b/src/library/scala/ScalaObject.scala @@ -11,6 +11,7 @@ package scala +import Predef._ trait ScalaObject extends AnyRef { |