From 4959e9f11c459e1c1eaa6cc168a4b9f2e784ffdf Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Fri, 28 Oct 2016 10:27:13 -0700 Subject: SI-6734 Comment --- .../scala/tools/nsc/typechecker/Typers.scala | 3 ++- test/files/pos/t6734.scala | 24 ++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index a92c190805..cca6f280e3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3140,13 +3140,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper // 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. // SI-6734 Locality test below is meaningless if we're not even in the correct tree. + // For modules that are synthetic case companions, check that case class is defined here. 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 t @ ClassDef(_, _, _, _) => t.symbol == cdef.symbol // cdef ne t case _ => false } case _ => true diff --git a/test/files/pos/t6734.scala b/test/files/pos/t6734.scala index f8fed0a27a..88932cd2cc 100644 --- a/test/files/pos/t6734.scala +++ b/test/files/pos/t6734.scala @@ -1,23 +1,17 @@ -//single file badimp.scala -// adding package object gives not found: type SortedMap -package object badimp +// desugars to package p { object `package` } +// previously, synthetic p.C was incorrectly added to this tree +// This only matters because synthetics are not hygienic +package object p -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 p { + import scala.concurrent.Future + case class C private[p] (value: Future[Int]) // private to avoid rewriting C.apply to new C } package client { trait X { - import scala.collection.immutable.SortedMap - def f = badimp.Nodal("test", SortedMap[String, Int]()) // ensure Nodal.apply was created + import scala.concurrent.Future + def f = p.C(Future(42)(null)) // ensure synthetics were generated, i.e., p.C.apply } } -- cgit v1.2.3