aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-06-29 19:05:20 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-11 13:34:59 +0200
commitaf43d325b778973ad9e144b5c27c455febb98890 (patch)
tree7803923eade05a15f0a5bbe3ef8b6fb86390643b /src/dotty/tools/dotc/core/Types.scala
parent850dc6f2fb3b6228f2586ce0790621e80f664afe (diff)
downloaddotty-af43d325b778973ad9e144b5c27c455febb98890.tar.gz
dotty-af43d325b778973ad9e144b5c27c455febb98890.tar.bz2
dotty-af43d325b778973ad9e144b5c27c455febb98890.zip
Abstract type parameters out from type symbols
In the new hk scheme, a type parameter can be represented by a refinement without a corresponding symbol. Therefore, we need to disentangle the info inherent in a type parameter from the contents of a type symbol. We achieve this by creating a common super trait "MemerInfo" of Symbol and RefinedType.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 5252a9149..cba13ef81 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -869,7 +869,7 @@ object Types {
def isParamName = tp.classSymbol.typeParams.exists(_.name == tp.refinedName)
if (refinementOK || isParamName) tp.underlying.underlyingClassRef(refinementOK)
else NoType
- case tp: RecType if refinementOK => tp.parent
+ case tp: RecType if refinementOK => tp.parent
case _ => NoType
}
@@ -2051,7 +2051,7 @@ object Types {
* given the refined type itself.
*/
abstract case class RefinedType(private var myParent: Type, refinedName: Name, private var myRefinedInfo: Type)
- extends RefinedOrRecType with BindingType {
+ extends RefinedOrRecType with BindingType with MemberBinding {
final def parent = myParent
final def refinedInfo = myRefinedInfo
@@ -2090,6 +2090,16 @@ object Types {
if (parent.member(refinedName).exists) derivedRefinedType(parent, refinedName, refinedInfo)
else parent
+ // MemberBinding methods
+ def isTypeParam(implicit ctx: Context) = refinedInfo match {
+ case tp: TypeBounds => tp.isBinding
+ case _ => false
+ }
+ def memberName(implicit ctx: Context) = refinedName
+ def memberBounds(implicit ctx: Context) = refinedInfo.bounds
+ def memberBoundsAsSeenFrom(pre: Type)(implicit ctx: Context) = memberBounds
+ def memberVariance(implicit ctx: Context) = BindingKind.toVariance(refinedInfo.bounds.bindingKind)
+
override def equals(that: Any) = that match {
case that: RefinedType =>
this.parent == that.parent &&
@@ -3120,7 +3130,10 @@ object Types {
object BindingKind {
def fromVariance(v: Int): BindingKind = new BindingKind((v + NonvariantBinding.n).toByte)
- def toVariance(bk: BindingKind): Int = bk.n
+ def toVariance(bk: BindingKind): Int = {
+ assert(bk.n != 0)
+ bk.n - NonvariantBinding.n
+ }
}
// ----- Annotated and Import types -----------------------------------------------