aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-29 13:15:28 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-29 13:16:55 +0100
commita80cf94570cdd7eaa1b7a9a8c82fe7e535688a91 (patch)
treed1dbcdd55c74d2550dbc98b1052c61fc74339889
parent03d0ffc637d650da2678619cfb84a09b08273787 (diff)
downloaddotty-a80cf94570cdd7eaa1b7a9a8c82fe7e535688a91.tar.gz
dotty-a80cf94570cdd7eaa1b7a9a8c82fe7e535688a91.tar.bz2
dotty-a80cf94570cdd7eaa1b7a9a8c82fe7e535688a91.zip
Fixing equality for selection protos
They no longer can be accidentally equal to refinement type. Todo: Disentangle selection protos entirely from Refinement types? See branch disentangle-selectproto.
-rw-r--r--src/dotty/tools/dotc/core/Types.scala5
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala14
2 files changed, 12 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 63c26a6e7..9357e8d51 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1266,6 +1266,8 @@ object Types {
override def underlying(implicit ctx: Context) = parent
+ protected def isProto: Boolean = false
+
/** Derived refined type, with a twist: A refinement with a higher-kinded type param placeholder
* is transformed to a refinement of the original type parameter if that one exists.
*/
@@ -1296,7 +1298,8 @@ object Types {
case that: RefinedType =>
this.parent == that.parent &&
this.refinedName == that.refinedName &&
- this.refinedInfo == that.refinedInfo
+ this.refinedInfo == that.refinedInfo &&
+ !that.isProto
case _ =>
false
}
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index e55bfb439..c7945e3b5 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -73,7 +73,7 @@ object Inferencing {
*
* [ ].name: proto
*/
- abstract class SelectionProto(val name: Name, proto: Type, compat: Compatibility)
+ abstract class SelectionProto(val name: Name, proto: Type, val compat: Compatibility)
extends RefinedType(WildcardType, name) with ProtoType {
override val refinedInfo = proto
override def isMatchedBy(tp1: Type)(implicit ctx: Context) =
@@ -81,6 +81,7 @@ object Inferencing {
val mbr = tp1.member(name)
mbr.exists && mbr.hasAltWith(m => compat.normalizedCompatible(m.info, proto))
}
+ override def isProto = true
override def toString = "Proto" + super.toString
override def derivedRefinedType(parent: Type, refinedName: Name, refinedInfo: Type)(implicit ctx: Context): RefinedType = {
val tp1 @ RefinedType(parent1, refinedName1) = super.derivedRefinedType(parent, refinedName, refinedInfo)
@@ -93,21 +94,22 @@ object Inferencing {
def derivedSelectionProto(name: Name, proto: Type, compat: Compatibility)(implicit ctx: Context) =
if ((name eq this.name) && (proto eq this.proto) && (compat eq this.compat)) this
else SelectionProto(name, proto, compat)
- /*
+
override def equals(that: Any): Boolean = that match {
case that: SelectionProto =>
- (name eq that.name) && (refinedInfo eq that.refinedInfo) && (compat eq that.compat)
+ (name eq that.name) && (refinedInfo == that.refinedInfo) && (compat eq that.compat)
+ case _ =>
+ false
}
-*/
def map(tm: TypeMap)(implicit ctx: Context) = derivedSelectionProto(name, tm(proto), compat)
def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context) = ta(x, this)
- }
- class CachedSelectionProto(name: Name, proto: Type, compat: Compatibility) extends SelectionProto(name, proto, compat) {
override def computeHash = addDelta(doHash(name, proto), if (compat == NoViewsAllowed) 1 else 0)
}
+ class CachedSelectionProto(name: Name, proto: Type, compat: Compatibility) extends SelectionProto(name, proto, compat)
+
object SelectionProto {
def apply(name: Name, proto: Type, compat: Compatibility)(implicit ctx: Context): SelectionProto = {
val rt = new CachedSelectionProto(name, proto, compat)