summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-09-01 09:12:13 -0700
committerPaul Phillips <paulp@improving.org>2012-09-01 09:12:13 -0700
commit6b87cdcd7bd6d1932e87e6bf8dc6029d6461a488 (patch)
tree80673a4aaf88e2c1b768730abef12309c0b4c208 /src
parentf275cff8ddb75fd041b040a6f5c1e019a43a2bff (diff)
parent34893e5d77b683dfd442162f7a5a28b6901c7080 (diff)
downloadscala-6b87cdcd7bd6d1932e87e6bf8dc6029d6461a488.tar.gz
scala-6b87cdcd7bd6d1932e87e6bf8dc6029d6461a488.tar.bz2
scala-6b87cdcd7bd6d1932e87e6bf8dc6029d6461a488.zip
Merge pull request #1227 from paulp/issue/6034
Fix for SI-6034, covariant value classes.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala3
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala1
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala9
3 files changed, 10 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
index 2831afc48e..0820d3e714 100644
--- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala
@@ -111,7 +111,8 @@ abstract class ExtensionMethods extends Transform with TypingTransformers {
}
def extensionMethInfo(extensionMeth: Symbol, origInfo: Type, clazz: Symbol): Type = {
- var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth)
+ // No variance for method type parameters
+ var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) map (_ resetFlag COVARIANT | CONTRAVARIANT)
val thisParamType = appliedType(clazz.typeConstructor, newTypeParams map (_.tpeHK))
val thisParam = extensionMeth.newValueParameter(nme.SELF, extensionMeth.pos) setInfo thisParamType
def transform(clonedType: Type): Type = clonedType match {
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 37f41e2868..2e045b08b9 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -516,6 +516,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def isTypeParameterOrSkolem = false
def isTypeSkolem = false
def isTypeMacro = false
+ def isInvariant = !isCovariant && !isContravariant
/** Qualities of Terms, always false for TypeSymbols.
*/
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 01f615c5cc..b13b893635 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -3712,10 +3712,15 @@ trait Types extends api.Types { self: SymbolTable =>
* may or may not be poly? (It filched the standard "canonical creator" name.)
*/
object GenPolyType {
- def apply(tparams: List[Symbol], tpe: Type): Type = (
+ def apply(tparams: List[Symbol], tpe: Type): Type = {
+ tpe match {
+ case MethodType(_, _) =>
+ assert(tparams forall (_.isInvariant), "Trying to create a method with variant type parameters: " + ((tparams, tpe)))
+ case _ =>
+ }
if (tparams.nonEmpty) typeFun(tparams, tpe)
else tpe // it's okay to be forgiving here
- )
+ }
def unapply(tpe: Type): Option[(List[Symbol], Type)] = tpe match {
case PolyType(tparams, restpe) => Some((tparams, restpe))
case _ => Some((Nil, tpe))