aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-10-02 13:15:35 +0200
committerGuillaume Martres <smarter@ubuntu.com>2016-10-11 19:21:02 +0200
commit2fe7e9220ab12336d4dcddbe9b523a736a6c17e8 (patch)
treee18b665db9b15652541a14b4428d5344bce266c8 /src
parent146bc29acaba58391a5462ee26f989debaac9038 (diff)
downloaddotty-2fe7e9220ab12336d4dcddbe9b523a736a6c17e8.tar.gz
dotty-2fe7e9220ab12336d4dcddbe9b523a736a6c17e8.tar.bz2
dotty-2fe7e9220ab12336d4dcddbe9b523a736a6c17e8.zip
Disallow singleton types in unions
For the moment, we do not know how to handle something like 1 | 2 or x.type | y.type correctly. So it's better to disallow these situations until we find a proper solution.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala5
2 files changed, 11 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 7ba66e3d8..3461facc1 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -542,6 +542,13 @@ trait Checking {
errorTree(tpt, ex"missing type parameter for ${tpt.tpe}")
}
else tpt
+
+ /** Check that `tpt` does not refer to a singleton type */
+ def checkNotSingleton(tpt: Tree, where: String)(implicit ctx: Context): Tree =
+ if (tpt.tpe.isInstanceOf[SingletonType]) {
+ errorTree(tpt, ex"Singleton type ${tpt.tpe} is not allowed $where")
+ }
+ else tpt
}
trait NoChecking extends Checking {
@@ -556,4 +563,5 @@ trait NoChecking extends Checking {
override def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = ()
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt
+ override def checkNotSingleton(tpt: Tree, where: String)(implicit ctx: Context): Tree = tpt
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index bbb20bcf5..e423082d5 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -999,8 +999,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
def typedOrTypeTree(tree: untpd.OrTypeTree)(implicit ctx: Context): OrTypeTree = track("typedOrTypeTree") {
- val left1 = typed(tree.left)
- val right1 = typed(tree.right)
+ val where = "in a union type"
+ val left1 = checkNotSingleton(typed(tree.left), where)
+ val right1 = checkNotSingleton(typed(tree.right), where)
assignType(cpy.OrTypeTree(tree)(left1, right1), left1, right1)
}