diff options
author | Martin Odersky <odersky@gmail.com> | 2016-10-02 13:15:35 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2016-10-11 19:21:02 +0200 |
commit | 2fe7e9220ab12336d4dcddbe9b523a736a6c17e8 (patch) | |
tree | e18b665db9b15652541a14b4428d5344bce266c8 /src/dotty/tools/dotc/typer/Checking.scala | |
parent | 146bc29acaba58391a5462ee26f989debaac9038 (diff) | |
download | dotty-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/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 8 |
1 files changed, 8 insertions, 0 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 } |