From 537e29676b0706de1855fe763b87732b846931f4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 25 Nov 2013 22:17:54 +0100 Subject: Dropping the Expanded when computing type parameter variances. Did not look like it was needed, after all; Local alone is enough. --- src/dotty/tools/dotc/core/Flags.scala | 4 ---- src/dotty/tools/dotc/core/SymDenotations.scala | 23 ++++++++--------------- src/dotty/tools/dotc/core/TypeApplications.scala | 4 ++-- src/dotty/tools/dotc/typer/Namer.scala | 2 +- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index 70761ebf3..956b67ffb 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -451,10 +451,6 @@ object Flags { /** An abstract class or a trait */ final val AbstractOrTrait = Abstract | Trait - /** A local symbol, or one which has an expanded name (type parameters go from one to the other). - */ - final val LocalOrExpanded = Local | ExpandedName - /** Labeled `private` or `protected[local]` */ final val PrivateOrLocal = Private | Local diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 08e9a407a..2727095cf 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -528,6 +528,8 @@ object SymDenotations { final def enclosingClass(implicit ctx: Context): Symbol = if (isClass) symbol else owner.enclosingClass + /** The class containing this denotation which has the given name. + */ final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = { val cls = enclosingClass if (cls.name == name) cls else cls.owner.enclosingClassNamed(name) @@ -537,16 +539,15 @@ object SymDenotations { * except for a toplevel module, where its module class is returned. */ final def topLevelClass(implicit ctx: Context): Symbol = { - val sym = topLevelSym + def topLevel(d: SymDenotation): Symbol = { + if ((d is PackageClass) || (d.owner is PackageClass)) d.symbol + else topLevel(d.owner) + } + val sym = topLevel(this) if (sym.isClass) sym else sym.moduleClass } - /** The top-level symbol containing this denotation. */ - final def topLevelSym(implicit ctx: Context): Symbol = - if ((this is PackageClass) || (owner is PackageClass)) symbol - else owner.topLevelSym - - /** The package containing this denotation */ + /** The package class containing this denotation */ final def enclosingPackage(implicit ctx: Context): Symbol = if (this is PackageClass) symbol else owner.enclosingPackage @@ -676,14 +677,6 @@ object SymDenotations { else if (this is Contravariant) -1 else 0 - /** If this is a privatye[this] or protected[this] type parameter or type member, - * its variance, otherwise 0. - */ - final def localVariance: Int = - if (this is LocalCovariant) 1 - else if (this is LocalContravariant) -1 - else 0 - override def toString = { val kindString = if (this is ModuleClass) "module class" diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 624a86b21..66b21eb5e 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -128,8 +128,8 @@ class TypeApplications(val self: Type) extends AnyVal { */ final def toBounds(tparam: Symbol)(implicit ctx: Context): TypeBounds = { val v = tparam.variance - if (v > 0 && !(tparam is LocalOrExpanded)) TypeBounds.upper(self) - else if (v < 0 && !(tparam is LocalOrExpanded)) TypeBounds.lower(self) + if (v > 0 && !(tparam is Local)) TypeBounds.upper(self) + else if (v < 0 && !(tparam is Local)) TypeBounds.lower(self) else TypeAlias(self, v) } diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 09ce41167..f8551d615 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -437,7 +437,7 @@ class Namer { typer: Typer => else rhsType case _ => if (tparamSyms.nonEmpty) rhsType.LambdaAbstract(tparamSyms)(ctx.error(_, _)) - else TypeAlias(rhsType, sym.localVariance) + else TypeAlias(rhsType, if (sym is Local) sym.variance else 0) } } } \ No newline at end of file -- cgit v1.2.3