summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-12-26 06:07:04 -0800
committerPaul Phillips <paulp@improving.org>2011-12-26 06:31:03 -0800
commitf737e35ddf43599043ab78404c4f9a13e6d02c9b (patch)
tree2582eea4b07fedd9476286dec9f05abef24c738e
parent8a862fd5e94a06c7fc1088623f594cd5bf864168 (diff)
downloadscala-f737e35ddf43599043ab78404c4f9a13e6d02c9b.tar.gz
scala-f737e35ddf43599043ab78404c4f9a13e6d02c9b.tar.bz2
scala-f737e35ddf43599043ab78404c4f9a13e6d02c9b.zip
Fixed regression in lub calculation.
Changing NullaryMethodType to be a SimpleTypeProxy because nearly all its operations forward to its result type was it seems not such a good idea, because it also meant that calling .underlying returned the result type rather than the method type. The way this materialized was in subtype checks of refinement types. A lub is calculated for two nullary method types in the course of calculating a refinement, and then the input types are checked against the calculated lub. However in the lub refinement, the nullary method type has become a bare typeref, and so the subtype check failed. Closes SI-5317. This does give me confidence that all the malformed lubs one sees logged under -Ydebug (and there are still many, especially with type constructors) are alerting us to real bugs elsewhere in Types.
-rw-r--r--src/compiler/scala/reflect/internal/Types.scala26
-rw-r--r--test/files/pos/t5317.scala12
2 files changed, 29 insertions, 9 deletions
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala
index 2db957410b..47184eee51 100644
--- a/src/compiler/scala/reflect/internal/Types.scala
+++ b/src/compiler/scala/reflect/internal/Types.scala
@@ -2153,15 +2153,23 @@ A type's typeSymbol should never be inspected directly.
override def isJava = true
}
- case class NullaryMethodType(override val resultType: Type) extends SimpleTypeProxy {
- override def underlying = resultType
- override def isTrivial = resultType.isTrivial && (resultType eq resultType.withoutAnnotations)
- override def paramSectionCount = 0
- override def paramss = Nil
- override def params = Nil
- override def paramTypes = Nil
- override def safeToString = "=> " + resultType
- override def kind = "NullaryMethodType"
+ case class NullaryMethodType(override val resultType: Type) extends Type {
+ override def isTrivial = resultType.isTrivial && (resultType eq resultType.withoutAnnotations)
+ override def prefix: Type = resultType.prefix
+ override def narrow: Type = resultType.narrow
+ override def finalResultType: Type = resultType.finalResultType
+ override def termSymbol: Symbol = resultType.termSymbol
+ override def typeSymbol: Symbol = resultType.typeSymbol
+ override def parents: List[Type] = resultType.parents
+ override def decls: Scope = resultType.decls
+ override def baseTypeSeq: BaseTypeSeq = resultType.baseTypeSeq
+ override def baseTypeSeqDepth: Int = resultType.baseTypeSeqDepth
+ override def baseClasses: List[Symbol] = resultType.baseClasses
+ override def baseType(clazz: Symbol): Type = resultType.baseType(clazz)
+ override def boundSyms = resultType.boundSyms
+ override def isVolatile = resultType.isVolatile
+ override def safeToString: String = "=> "+ resultType
+ override def kind = "NullaryMethodType"
}
object NullaryMethodType extends NullaryMethodTypeExtractor
diff --git a/test/files/pos/t5317.scala b/test/files/pos/t5317.scala
new file mode 100644
index 0000000000..8c9c9d8222
--- /dev/null
+++ b/test/files/pos/t5317.scala
@@ -0,0 +1,12 @@
+object Test {
+ trait S { type T; val x: AnyRef }
+ trait A extends S { type T <: A; val x: A = null }
+ trait B extends S { type T <: B; val x: B = null }
+
+ val a = new A{}
+ val b = new B{}
+ val y = if (true) a else b
+
+ // lub of y should allow for this
+ println(y.x.x)
+}