aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-12-13 14:09:27 +0100
committerMartin Odersky <odersky@gmail.com>2014-12-13 14:09:27 +0100
commit291b563418011120c9fbe05a05e118a7ec28005d (patch)
treebf5a86dd05fbbf2ee6614d4c3e43e265197abe58 /src/dotty/tools/dotc/core/Types.scala
parent7cdf3d0dc5709634825b1300d77d1a0ef01c69fa (diff)
downloaddotty-291b563418011120c9fbe05a05e118a7ec28005d.tar.gz
dotty-291b563418011120c9fbe05a05e118a7ec28005d.tar.bz2
dotty-291b563418011120c9fbe05a05e118a7ec28005d.zip
Fix #248: Class cannot inherit from refinement types
We now check that classes do not inherit from refinement types (unless they are an encoding of parameterized types), nor from & or | types.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 017b7cadc..987014ff4 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -700,15 +700,20 @@ object Types {
/** If this is a (possibly aliased, annotated, and/or parameterized) reference to
* a class, the class type ref, otherwise NoType.
+ * @param refinementOK If `true` we also skip non-parameter refinements.
*/
- def underlyingClassRef(implicit ctx: Context): Type = dealias match {
+ def underlyingClassRef(refinementOK: Boolean)(implicit ctx: Context): Type = dealias match {
case tp: TypeRef =>
if (tp.symbol.isClass) tp
- else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef
+ else if (tp.symbol.isAliasType) tp.underlying.underlyingClassRef(refinementOK)
else NoType
- case tp: TypeVar => tp.underlying.underlyingClassRef
- case tp: AnnotatedType => tp.underlying.underlyingClassRef
- case tp: RefinedType => tp.underlying.underlyingClassRef
+ case tp: AnnotatedType => tp.underlying.underlyingClassRef(refinementOK)
+ case tp: RefinedType =>
+ if (refinementOK) tp.underlying.underlyingClassRef(refinementOK)
+ else {
+ val tycon = tp.withoutArgs(tp.argInfos)
+ if (tycon eq tp) NoType else tycon.underlyingClassRef(refinementOK)
+ }
case _ => NoType
}