File tree 2 files changed +11
-8
lines changed
compiler/src/dotty/tools/dotc/ast
2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -344,13 +344,6 @@ object desugar {
344
344
// new C[Ts](paramss)
345
345
lazy val creatorExpr = New (classTypeRef, constrVparamss nestedMap refOfDef)
346
346
347
- // The return type of the `apply` and `copy` methods
348
- val applyResultTpt =
349
- if (isEnumCase)
350
- if (parents.isEmpty) enumClassTypeRef
351
- else parents.head
352
- else TypeTree ()
353
-
354
347
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
355
348
// def isDefined = true
356
349
// def productArity = N
@@ -436,6 +429,13 @@ object desugar {
436
429
// For all other classes, the parent is AnyRef.
437
430
val companions =
438
431
if (isCaseClass) {
432
+ // The return type of the `apply` method
433
+ val applyResultTpt =
434
+ if (isEnumCase)
435
+ if (parents.isEmpty) enumClassTypeRef
436
+ else parents.reduceLeft(AndTypeTree )
437
+ else TypeTree ()
438
+
439
439
val parent =
440
440
if (constrTparams.nonEmpty ||
441
441
constrVparamss.length > 1 ||
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ enum class Option[+T] extends Serializable {
2
2
def isDefined : Boolean
3
3
}
4
4
object Option {
5
+ def apply [T ](x : T ): Option [T ] = if (x == null ) None else Some (x)
5
6
case Some (x : T ) {
6
7
def isDefined = true
7
8
}
@@ -11,6 +12,8 @@ object Option {
11
12
}
12
13
13
14
object Test {
14
- def main (args : Array [String ]) =
15
+ def main (args : Array [String ]) = {
15
16
assert(Some (None ).isDefined)
17
+ Option (22 ) match { case Option .Some (x) => assert(x == 22 ) }
18
+ }
16
19
}
You can’t perform that action at this time.
0 commit comments