aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/ast/Desugar.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-28 18:59:08 +0100
committerMartin Odersky <odersky@gmail.com>2017-04-04 13:29:38 +0200
commit44d9ab81886a9ff0b7256fccb584c049f1c18027 (patch)
treeeff314cd55d1917ed9f1cb1d6caba551a3f04a51 /compiler/src/dotty/tools/dotc/ast/Desugar.scala
parent91a26b3f42d1218015acb9b7e1bfc180e3ed779b (diff)
downloaddotty-44d9ab81886a9ff0b7256fccb584c049f1c18027.tar.gz
dotty-44d9ab81886a9ff0b7256fccb584c049f1c18027.tar.bz2
dotty-44d9ab81886a9ff0b7256fccb584c049f1c18027.zip
Support cases with type parameters that extend a non-parameterized base
Support cases with type parameters that implicitly extend a non-parameterized base without needing their own extends clause. The proposal has been updated to make clear that this is supported. Also address other reviewers comments.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Desugar.scala20
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
index 04834b04b..80da75678 100644
--- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
@@ -296,11 +296,16 @@ object desugar {
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
+ lazy val reconstitutedTypeParams = reconstitutedEnumTypeParams(cdef.pos.startPos)
+
val originalTparams =
if (isEnumCase && parents.isEmpty) {
- if (constr1.tparams.nonEmpty)
- ctx.error(em"case with type parameters needs extends clause", constr1.tparams.head.pos)
- reconstitutedEnumTypeParams(cdef.pos.startPos)
+ if (constr1.tparams.nonEmpty) {
+ if (reconstitutedTypeParams.nonEmpty)
+ ctx.error(em"case with type parameters needs extends clause", constr1.tparams.head.pos)
+ constr1.tparams
+ }
+ else reconstitutedTypeParams
}
else constr1.tparams
val originalVparamss = constr1.vparamss
@@ -339,7 +344,9 @@ object desugar {
// a reference to the class type bound by `cdef`, with type parameters coming from the constructor
val classTypeRef = appliedRef(classTycon)
// a reference to `enumClass`, with type parameters coming from the constructor
- lazy val enumClassTypeRef = appliedRef(enumClassRef)
+ lazy val enumClassTypeRef =
+ if (reconstitutedTypeParams.isEmpty) enumClassRef
+ else appliedRef(enumClassRef)
// new C[Ts](paramss)
lazy val creatorExpr = New(classTypeRef, constrVparamss nestedMap refOfDef)
@@ -516,10 +523,7 @@ object desugar {
case _ =>
}
- val result = flatTree(cdef1 :: companions ::: implicitWrappers)
- //if (isEnum) println(i"enum $cdef\n --->\n$result")
- //if (isEnumCase) println(i"enum case $cdef\n --->\n$result")
- result
+ flatTree(cdef1 :: companions ::: implicitWrappers)
}
val AccessOrSynthetic = AccessFlags | Synthetic