aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeComparer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 19:12:29 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:34:59 +0200
commit5daae278392ed6fabd45c9fa55aded970ca2a348 (patch)
tree3ddec4b259a4c359efdff5fa4392a88819d336fe /src/dotty/tools/dotc/core/TypeComparer.scala
parent4bf43f82c88dbeb0578e289b37ce1a7580aa22f2 (diff)
downloaddotty-5daae278392ed6fabd45c9fa55aded970ca2a348.tar.gz
dotty-5daae278392ed6fabd45c9fa55aded970ca2a348.tar.bz2
dotty-5daae278392ed6fabd45c9fa55aded970ca2a348.zip
Multiple fixes
- Swap order of tests in lookupRefined - Change joins of BindingKinds. A type parameter joint with a normal refinement represents a type parameter that has been filled in. So the Binding attribute should be removed. - Fix printing of type lambdas under new hk scheme - refine isRef for hk type The new definition avoids that a higher-kinded type "isRef" of an underlying class. I.e. `[X] -> Any` is not longer a ref to `Any`. - Fix withBindingKind for type aliases Old definition converted aliases to type bounds. - Multiple fixes to BetaReduce - Fix logic for hk subtype tests - Make isHK more precise
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeComparer.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 3648b3764..b0c36ca58 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -354,12 +354,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case tp2: RefinedType =>
def compareRefinedSlow: Boolean = {
val name2 = tp2.refinedName
- if (name2.isHkArgName) {
- val tp2reduced = tp2.BetaReduce
- if (Config.newHK && (tp2reduced ne tp2)) return isSubType(tp1, tp2reduced)
- if (Config.newHK && tp2.isTypeParam) return compareHkLambda(tp2, tp1, inOrder = false)
- if (Config.newHK && !tp1.isHKApply) return compareHkApply(tp2, tp1, inOrder = false)
- }
isSubType(tp1, tp2.parent) &&
(name2 == nme.WILDCARD || hasMatchingMember(name2, tp1, tp2))
}
@@ -374,10 +368,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
// This twist is needed to make collection/generic/ParFactory.scala compile
fourthTry(tp1, tp2) || compareRefinedSlow
case _ =>
- compareRefinedSlow ||
- fourthTry(tp1, tp2) ||
compareHkApply(tp2, tp1, inOrder = false) ||
compareHkLambda(tp2, tp1, inOrder = false) ||
+ compareRefinedSlow ||
+ fourthTry(tp1, tp2) ||
compareAliasedRefined(tp2, tp1, inOrder = false)
}
else // fast path, in particular for refinements resulting from parameterization.
@@ -501,15 +495,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
}
isNewSubType(tp1.underlying.widenExpr, tp2) || comparePaths
case tp1: RefinedType =>
- if (Config.newHK && tp1.refinedName.isHkArgName) {
- val tp1reduced = tp1.BetaReduce
- if (Config.newHK && (tp1reduced ne tp1)) return isSubType(tp1reduced, tp2)
- if (Config.newHK && tp1.isTypeParam) return compareHkLambda(tp1, tp2, inOrder = true)
- if (Config.newHK && !tp2.isHKApply) return compareHkApply(tp1, tp2, inOrder = true)
- }
isNewSubType(tp1.parent, tp2) ||
- !Config.newHK && compareHkLambda(tp1, tp2, inOrder = true) ||
- !Config.newHK && compareAliasedRefined(tp1, tp2, inOrder = true)
+ compareHkApply(tp1, tp2, inOrder = true) ||
+ compareHkLambda(tp1, tp2, inOrder = true) ||
+ compareAliasedRefined(tp1, tp2, inOrder = true)
case tp1: RecType =>
isNewSubType(tp1.parent, tp2)
case AndType(tp11, tp12) =>
@@ -609,7 +598,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
val hkTypeParams = param.typeParams
subtyping.println(i"classBounds = ${projection.prefix.member(tpnme.hkApplyOBS).info.classSymbols}")
subtyping.println(i"base classes = ${other.baseClasses}")
- subtyping.println(i"type params = $hkTypeParams")
+ subtyping.println(i"type params = ${hkTypeParams.map(_.memberName)}")
if (inOrder) unifyWith(other)
else testLifted(other, projection.prefix, hkTypeParams, unifyWith)
case _ =>
@@ -671,13 +660,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
false
}
}
- Config.newHK && app.isHKApply && !other.isHKApply && tryInfer(app.typeConstructor.dealias)
+ Config.newHK && app.isHKApply && !other.isHKApply && {
+ val reduced = app.BetaReduce(shortLived = true)
+ if (reduced ne app)
+ if (inOrder) isSubType(reduced, other) else isSubType(other, reduced)
+ else tryInfer(app.typeConstructor.dealias)
+ }
}
/** Compare type lambda with non-lambda type. */
def compareHkLambda(rt: RefinedType, other: Type, inOrder: Boolean) = rt match {
case TypeLambda(args, body) =>
- other.isInstanceOf[TypeRef] &&
args.length == other.typeParams.length && {
val applied = other.appliedTo(argRefs(rt, args.length))
if (inOrder) isSubType(body, applied)
@@ -1510,7 +1503,7 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
override def compareHkApply(app: RefinedType, other: Type, inOrder: Boolean) =
if (app.isHKApply)
- traceIndented(i"compareHkApply $app, $other, $inOrder, ${app.typeConstructor.dealias}") {
+ traceIndented(i"compareHkApply $app, $other, $inOrder, ${app.BetaReduce(shortLived = true)}") {
super.compareHkApply(app, other, inOrder)
}
else super.compareHkApply(app, other, inOrder)