From f737e35ddf43599043ab78404c4f9a13e6d02c9b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 26 Dec 2011 06:07:04 -0800 Subject: 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. --- src/compiler/scala/reflect/internal/Types.scala | 26 ++++++++++++++++--------- test/files/pos/t5317.scala | 12 ++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 test/files/pos/t5317.scala 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) +} -- cgit v1.2.3