summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiles Sabin <miles@milessabin.com>2016-08-10 09:30:49 +0100
committerMiles Sabin <miles@milessabin.com>2016-11-28 10:49:43 +0000
commitdde13b56f421a6f956abebc58f041acec8744149 (patch)
treeda787e48245d7ddb62fe4f1e1224ebae89fdc161 /src
parent690ba800ec04f05c0f5e5e369863ab5b9578d42f (diff)
downloadscala-dde13b56f421a6f956abebc58f041acec8744149.tar.gz
scala-dde13b56f421a6f956abebc58f041acec8744149.tar.bz2
scala-dde13b56f421a6f956abebc58f041acec8744149.zip
Partial fix for SI-7046
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala6
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala31
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala11
-rw-r--r--src/reflect/scala/reflect/internal/StdAttachments.scala6
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala17
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala5
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala1
8 files changed, 76 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index a7880c72d7..69a54193e0 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -182,6 +182,19 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
}
}
+ private var propCnt = 0
+ @inline final def withPropagateCyclicReferences[T](t: => T): T = {
+ try {
+ propCnt = propCnt+1
+ t
+ } finally {
+ propCnt = propCnt-1
+ assert(propCnt >= 0)
+ }
+ }
+
+ def propagateCyclicReferences: Boolean = propCnt > 0
+
/** Representing ASTs as graphs */
object treeBrowsers extends {
val global: Global.this.type = Global.this
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
index fcfcc8feb9..2d8d591b6d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
@@ -655,9 +655,6 @@ trait ContextErrors {
def ParentFinalInheritanceError(parent: Tree, mixin: Symbol) =
NormalTypeError(parent, "illegal inheritance from final "+mixin)
- def ParentSealedInheritanceError(parent: Tree, psym: Symbol) =
- NormalTypeError(parent, "illegal inheritance from sealed " + psym )
-
def ParentSelfTypeConformanceError(parent: Tree, selfType: Type) =
NormalTypeError(parent,
"illegal inheritance;\n self-type "+selfType+" does not conform to "+
@@ -1172,6 +1169,9 @@ trait ContextErrors {
def MissingParameterOrValTypeError(vparam: Tree) =
issueNormalTypeError(vparam, "missing parameter type")
+ def ParentSealedInheritanceError(parent: Tree, psym: Symbol) =
+ NormalTypeError(parent, "illegal inheritance from sealed " + psym )
+
def RootImportError(tree: Tree) =
issueNormalTypeError(tree, "_root_ cannot be imported")
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 78e8c8c073..7ffc6c6b48 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -115,7 +115,7 @@ trait Namers extends MethodSynthesis {
protected def owner = context.owner
def contextFile = context.unit.source.file
def typeErrorHandler[T](tree: Tree, alt: T): PartialFunction[Throwable, T] = {
- case ex: TypeError =>
+ case ex: TypeError if !global.propagateCyclicReferences =>
// H@ need to ensure that we handle only cyclic references
TypeSigError(tree, ex)
alt
@@ -1028,12 +1028,33 @@ trait Namers extends MethodSynthesis {
private def templateSig(templ: Template): Type = {
val clazz = context.owner
+
+ val parentTrees = typer.typedParentTypes(templ)
+
+ val pending = mutable.ListBuffer[AbsTypeError]()
+ parentTrees foreach { tpt =>
+ val ptpe = tpt.tpe
+ if(!ptpe.isError) {
+ val psym = ptpe.typeSymbol
+ val sameSourceFile = context.unit.source.file == psym.sourceFile
+
+ if (psym.isSealed && !phase.erasedTypes)
+ if (sameSourceFile)
+ psym addChild context.owner
+ else
+ pending += ParentSealedInheritanceError(tpt, psym)
+ if (psym.isLocalToBlock && !phase.erasedTypes)
+ psym addChild context.owner
+ }
+ }
+ pending.foreach(ErrorUtils.issueTypeError)
+
def checkParent(tpt: Tree): Type = {
if (tpt.tpe.isError) AnyRefTpe
else tpt.tpe
}
- val parents = typer.typedParentTypes(templ) map checkParent
+ val parents = parentTrees map checkParent
enterSelf(templ.self)
@@ -1827,6 +1848,12 @@ trait Namers extends MethodSynthesis {
abstract class TypeCompleter extends LazyType {
val tree: Tree
+ override def forceDirectSuperclasses: Unit = {
+ tree.foreach {
+ case dt: DefTree => global.withPropagateCyclicReferences(Option(dt.symbol).map(_.maybeInitialize))
+ case _ =>
+ }
+ }
}
def mkTypeCompleter(t: Tree)(c: Symbol => Unit) = new LockingTypeCompleter with FlagAgnosticCompleter {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index cca6f280e3..ef1586c831 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1677,7 +1677,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
supertpts mapConserve (tpt => checkNoEscaping.privates(context.owner, tpt))
}
catch {
- case ex: TypeError =>
+ case ex: TypeError if !global.propagateCyclicReferences =>
// fallback in case of cyclic errors
// @H none of the tests enter here but I couldn't rule it out
// upd. @E when a definition inherits itself, we end up here
@@ -1738,13 +1738,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
context.deprecationWarning(parent.pos, psym, report, version)
}
- if (psym.isSealed && !phase.erasedTypes)
- if (sameSourceFile)
- psym addChild context.owner
- else
- pending += ParentSealedInheritanceError(parent, psym)
- if (psym.isLocalToBlock && !phase.erasedTypes)
- psym addChild context.owner
val parentTypeOfThis = parent.tpe.dealias.typeOfThis
if (!(selfType <:< parentTypeOfThis) &&
@@ -5548,6 +5541,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
try runTyper() catch {
+ case ex: CyclicReference if global.propagateCyclicReferences =>
+ throw ex
case ex: TypeError =>
tree.clearType()
// The only problematic case are (recoverable) cyclic reference errors which can pop up almost anywhere.
diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala
index fd8f51cfb1..fc49de1cf6 100644
--- a/src/reflect/scala/reflect/internal/StdAttachments.scala
+++ b/src/reflect/scala/reflect/internal/StdAttachments.scala
@@ -81,4 +81,10 @@ trait StdAttachments {
/** An attachment carrying information between uncurry and erasure */
case class TypeParamVarargsAttachment(val typeParamRef: Type)
+
+ /** Attached to a class symbol to indicate that its children have been observed
+ * via knownDirectSubclasses. Children added subsequently will trigger an
+ * error to indicate that the earlier observation was incomplete.
+ */
+ case object KnownDirectSubclassesCalled extends PlainAttachment
}
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 56b6dc078d..68835d55dd 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -117,6 +117,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def knownDirectSubclasses = {
// See `getFlag` to learn more about the `isThreadsafe` call in the body of this method.
if (!isCompilerUniverse && !isThreadsafe(purpose = AllOps)) initialize
+
+ enclosingPackage.info.decls.foreach { sym =>
+ if(sourceFile == sym.sourceFile) {
+ sym.rawInfo.forceDirectSuperclasses
+ }
+ }
+
+ if(!isPastTyper)
+ updateAttachment(KnownDirectSubclassesCalled)
+
children
}
@@ -3291,7 +3301,12 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
private[this] var childSet: Set[Symbol] = Set()
override def children = childSet
- override def addChild(sym: Symbol) { childSet = childSet + sym }
+ override def addChild(sym: Symbol) {
+ if(!isPastTyper && hasAttachment[KnownDirectSubclassesCalled.type] && !childSet.contains(sym))
+ globalError(s"knownDirectSubclasses of ${this.name} observed before subclass ${sym.name} registered")
+
+ childSet = childSet + sym
+ }
def anonOrRefinementString = {
if (hasCompleteInfo) {
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index f8679616d1..9bb69e8516 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -315,6 +315,11 @@ trait Types
/** If this is a lazy type, assign a new type to `sym`. */
def complete(sym: Symbol) {}
+ /** If this is a lazy type corresponding to a subclass add it to its
+ * parents children
+ */
+ def forceDirectSuperclasses: Unit = ()
+
/** The term symbol associated with the type
* Note that the symbol of the normalized type is returned (@see normalize)
*/
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index dbafbfc6ba..d5d62b2203 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -48,6 +48,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
this.OuterArgCanBeElided
this.UseInvokeSpecial
this.TypeParamVarargsAttachment
+ this.KnownDirectSubclassesCalled
this.noPrint
this.typeDebug
this.Range