aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/ast/Desugar.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-27 17:44:02 +0100
committerMartin Odersky <odersky@gmail.com>2017-04-04 13:29:38 +0200
commit91a26b3f42d1218015acb9b7e1bfc180e3ed779b (patch)
tree63ba813e4b2a806da9f170624f03bad72d0e08dd /compiler/src/dotty/tools/dotc/ast/Desugar.scala
parentcf10e28a54aaeab124f9a939f71da7e09d299bcb (diff)
downloaddotty-91a26b3f42d1218015acb9b7e1bfc180e3ed779b.tar.gz
dotty-91a26b3f42d1218015acb9b7e1bfc180e3ed779b.tar.bz2
dotty-91a26b3f42d1218015acb9b7e1bfc180e3ed779b.zip
Support comma-separated enum constants
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Desugar.scala18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
index 575af97f4..04834b04b 100644
--- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
@@ -576,11 +576,23 @@ object desugar {
/** val p1, ..., pN: T = E
* ==>
* makePatDef[[val p1: T1 = E]]; ...; makePatDef[[val pN: TN = E]]
+ *
+ * case e1, ..., eN
+ * ==>
+ * expandSimpleEnumCase([case e1]); ...; expandSimpleEnumCase([case eN])
*/
- def patDef(pdef: PatDef)(implicit ctx: Context): Tree = {
+ def patDef(pdef: PatDef)(implicit ctx: Context): Tree = flatTree {
val PatDef(mods, pats, tpt, rhs) = pdef
- val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
- flatTree(pats1 map (makePatDef(pdef, mods, _, rhs)))
+ if (mods.hasMod[Mod.EnumCase] && enumCaseIsLegal(pdef))
+ pats map {
+ case id: Ident =>
+ expandSimpleEnumCase(id.name.asTermName, mods,
+ Position(pdef.pos.start, id.pos.end, id.pos.start))
+ }
+ else {
+ val pats1 = if (tpt.isEmpty) pats else pats map (Typed(_, tpt))
+ pats1 map (makePatDef(pdef, mods, _, rhs))
+ }
}
/** If `pat` is a variable pattern,