diff options
author | Martin Odersky <odersky@gmail.com> | 2014-03-19 17:56:03 +0100 |
---|---|---|
committer | Tobias Schlatter <tobias@meisch.ch> | 2014-03-21 11:28:30 +0100 |
commit | d6df293d2120f2247198cb6646a23c338f7dcbbf (patch) | |
tree | 6e5fe081dd2cd2f25b745bfd6e99328313b57ce8 /src/dotty/tools/dotc/core/Types.scala | |
parent | 40202eedb940d0614c08b1ba36c8648ed56ea332 (diff) | |
download | dotty-d6df293d2120f2247198cb6646a23c338f7dcbbf.tar.gz dotty-d6df293d2120f2247198cb6646a23c338f7dcbbf.tar.bz2 dotty-d6df293d2120f2247198cb6646a23c338f7dcbbf.zip |
Fix of t1236: higher-kinded
(and also of t0625, which reappeared).
Several fixes were made. In summary:
1. Naming and representation of KigherKinded traits changed. It's now $HigherKinded$NIP where
the letters after the second $ indicate variance (N)egative, (I)nvariant, (P)ositive. The HKtraits
themselves are always non-variant in their parameters.
2. When deriving refined types over higher-kinded types, the variance of a type alias
is the variance of the new type constructor.
3. isSubTypeHK was changed, as was the position from where it is called.
4. appliedTo also works for PolyTypes.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 967421f2b..38c07d99a 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -123,7 +123,7 @@ object Types { final def isLegalPrefix(implicit ctx: Context): Boolean = isStable || { val absTypeNames = memberNames(abstractTypeNameFilter) - if (absTypeNames.nonEmpty) typr.println(s"abstract type members of ${this.showWithUnderlying}: $absTypeNames") + if (absTypeNames.nonEmpty) typr.println(s"abstract type members of ${this.showWithUnderlying()}: $absTypeNames") absTypeNames.isEmpty } @@ -815,11 +815,11 @@ object Types { /** Convert to text */ def toText(printer: Printer): Text = printer.toText(this) - /** Utility method to show the underlying type of a TypeProxy together + /** Utility method to show the underlying type of a TypeProxy chain together * with the proxy type itself. */ - def showWithUnderlying(implicit ctx: Context): String = this match { - case tp: TypeProxy => s"$show with underlying ${tp.underlying.show}" + def showWithUnderlying(n: Int = 1)(implicit ctx: Context): String = this match { + case tp: TypeProxy if n > 0 => s"$show with underlying ${tp.underlying.showWithUnderlying(n - 1)}" case _ => show } @@ -1309,12 +1309,13 @@ object Types { lazy val underlyingTypeParams = parent.safeUnderlyingTypeParams lazy val originalTypeParam = underlyingTypeParams(refinedName.hkParamIndex) - /** drop any co/contra variance in refined info if variance disagrees - * with new type param + /** Use variance of newly instantiated type parameter rather than the old hk argument */ - def adjustedHKRefinedInfo(hkBounds: TypeBounds) = { - if (hkBounds.variance == originalTypeParam.info.bounds.variance) hkBounds - else TypeBounds(hkBounds.lo, hkBounds.hi) + def adjustedHKRefinedInfo(hkBounds: TypeBounds, underlyingTypeParam: TypeSymbol) = hkBounds match { + case tp @ TypeBounds(lo, hi) if lo eq hi => + tp.derivedTypeBounds(lo, hi, underlyingTypeParam.variance) + case _ => + hkBounds } if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) @@ -1323,7 +1324,8 @@ object Types { // && { println(s"deriving $refinedName $parent $underlyingTypeParams"); true } && refinedName.hkParamIndex < underlyingTypeParams.length && originalTypeParam.name != refinedName) - derivedRefinedType(parent, originalTypeParam.name, adjustedHKRefinedInfo(refinedInfo.bounds)) + derivedRefinedType(parent, originalTypeParam.name, + adjustedHKRefinedInfo(refinedInfo.bounds, underlyingTypeParams(refinedName.hkParamIndex))) else RefinedType(parent, refinedName, rt => refinedInfo.substThis(this, RefinedThis(rt))) } |