summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala20
-rw-r--r--test/files/pos/t6734.scala23
2 files changed, 40 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 7d48c548a1..a92c190805 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3139,10 +3139,24 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
val initElems = scope.elems
// SI-5877 The decls of a package include decls of the package object. But we don't want to add
// the corresponding synthetics to the package class, only to the package object class.
- def shouldAdd(sym: Symbol) =
- inBlock || !context.isInPackageObject(sym, context.owner)
+ // SI-6734 Locality test below is meaningless if we're not even in the correct tree.
+ def shouldAdd(sym: Symbol): Boolean = {
+ def shouldAddAsModule: Boolean =
+ sym.moduleClass.attachments.get[ClassForCaseCompanionAttachment] match {
+ case Some(att) =>
+ val cdef = att.caseClass
+ stats.exists {
+ case t @ ClassDef(_, _, _, _) => t.symbol == cdef.symbol
+ case _ => false
+ }
+ case _ => true
+ }
+
+ (!sym.isModule || shouldAddAsModule) && (inBlock || !context.isInPackageObject(sym, context.owner))
+ }
for (sym <- scope)
- for (tree <- context.unit.synthetics get sym if shouldAdd(sym)) { // OPT: shouldAdd is usually true. Call it here, rather than in the outer loop
+ // OPT: shouldAdd is usually true. Call it here, rather than in the outer loop
+ for (tree <- context.unit.synthetics.get(sym) if shouldAdd(sym)) {
newStats += typedStat(tree) // might add even more synthetics to the scope
context.unit.synthetics -= sym
}
diff --git a/test/files/pos/t6734.scala b/test/files/pos/t6734.scala
new file mode 100644
index 0000000000..f8fed0a27a
--- /dev/null
+++ b/test/files/pos/t6734.scala
@@ -0,0 +1,23 @@
+
+//single file badimp.scala
+// adding package object gives not found: type SortedMap
+package object badimp
+
+package badimp {
+
+ // move before package object works
+ import scala.collection.immutable.SortedMap
+
+ case class Nodal private[badimp] (value: String, children: SortedMap[String, Int])
+
+ // adding target object restores sanity
+ // but adding it before the import does not
+ //object Nodal
+}
+
+package client {
+ trait X {
+ import scala.collection.immutable.SortedMap
+ def f = badimp.Nodal("test", SortedMap[String, Int]()) // ensure Nodal.apply was created
+ }
+}