From 0fc19e0e1ef7b56f9ca0649fde35765892cf1a53 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 9 Oct 2013 12:36:43 +0200 Subject: Cleanup of new scheme for handling local type parameters and type members. If a type parameter or local type member is co/contravariant, its instantiation is a special alias type that remembers the variance. These alias types can be refined with subtypes in subclasses and intersection and union translate to their bounds. --- src/dotty/tools/dotc/core/SymDenotations.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala') diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 8a4cdf1e5..9142e3185 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -117,7 +117,7 @@ object SymDenotations { } protected[dotc] final def info_=(tp: Type) = { - def illegal: String = s"illegal type for module $this: $tp" + def illegal: String = s"illegal type for $this: $tp" /* if (this is Module) // make sure module invariants that allow moduleClass and sourceModule to work are kept. tp match { @@ -646,7 +646,7 @@ object SymDenotations { def symRef(implicit ctx: Context): NamedType = NamedType.withSym(owner.thisType, symbol) - /** The variance of this type parameter as an Int, with + /** The variance of this type parameter or type member as an Int, with * +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter */ final def variance: Int = @@ -654,6 +654,14 @@ 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" -- cgit v1.2.3