aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-02-01 00:08:26 +0100
committerMartin Odersky <odersky@gmail.com>2016-02-09 09:43:07 +0100
commitdefba2af7c3b49231962a6f882173bcaff914fcc (patch)
tree16149a87ac1422d5eac51e4e563f56eda743562c /src/dotty/tools
parent3637e08033c857e19862ae1fc9730d96cdba3fe2 (diff)
downloaddotty-defba2af7c3b49231962a6f882173bcaff914fcc.tar.gz
dotty-defba2af7c3b49231962a6f882173bcaff914fcc.tar.bz2
dotty-defba2af7c3b49231962a6f882173bcaff914fcc.zip
Check that non-abstract classes have realizable bounds.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala25
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala7
2 files changed, 22 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 882ab9f10..227dbb90f 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -449,16 +449,21 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
case _ => false
}
if (!isConcrete(tp)) NotConcrete
- else {
- def hasBadBounds(mbr: SingleDenotation) = {
- val bounds = mbr.info.bounds
- !(bounds.lo <:< bounds.hi)
- }
- tp.nonClassTypeMembers.find(hasBadBounds) match {
- case Some(mbr) => new HasProblemBounds(mbr)
- case _ => Realizable
- }
- }
+ else boundsRealizability(tp)
+ }
+
+ /** `Realizable` is `tp` has good bounds, a `HasProblemBounds` instance
+ * pointing to a bad bounds member otherwise.
+ */
+ def boundsRealizability(tp: Type)(implicit ctx: Context) = {
+ def hasBadBounds(mbr: SingleDenotation) = {
+ val bounds = mbr.info.bounds
+ !(bounds.lo <:< bounds.hi)
+ }
+ tp.nonClassTypeMembers.find(hasBadBounds) match {
+ case Some(mbr) => new HasProblemBounds(mbr)
+ case _ => Realizable
+ }
}
private def enterArgBinding(formal: Symbol, info: Type, cls: ClassSymbol, decls: Scope) = {
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index ca7c5c5ab..7e90d755b 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -330,6 +330,13 @@ trait Checking {
}
}
+ /** Check that all type members of `tp` have realizable bounds */
+ def checkRealizableBounds(tp: Type, pos: Position)(implicit ctx: Context): Unit = {
+ val rstatus = ctx.boundsRealizability(tp)
+ if (rstatus ne TypeOps.Realizable)
+ ctx.error(i"$tp cannot be instantiated since it${rstatus.msg}", pos)
+ }
+
/** Check that `tp` is a class type with a stable prefix. Also, if `traitReq` is
* true check that `tp` is a trait.
* Stability checking is disabled in phases after RefChecks.