@@ -291,7 +291,8 @@ object desugar {
291
291
case _ => false
292
292
}
293
293
294
- val isCaseClass = mods.is(Case ) && ! mods.is(Module )
294
+ val isCaseClass = mods.is(Case ) && ! mods.is(Module )
295
+ val isCaseObject = mods.is(Case ) && mods.is(Module )
295
296
val isEnum = mods.hasMod[Mod .Enum ]
296
297
val isEnumCase = isLegalEnumCase(cdef)
297
298
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
@@ -360,7 +361,7 @@ object desugar {
360
361
// pN: TN = pN: @uncheckedVariance)(moreParams) =
361
362
// new C[...](p1, ..., pN)(moreParams)
362
363
//
363
- // Above arity 22 we also synthesize:
364
+ // To add to both case classes and objects
364
365
// def productArity = N
365
366
// def productElement(i: Int): Any = i match { ... }
366
367
//
@@ -414,33 +415,21 @@ object desugar {
414
415
}
415
416
}
416
417
417
- // Above MaxTupleArity we extend Product instead of ProductN, in this
418
- // case we need to synthesise productElement & productArity.
419
- def largeProductMeths =
420
- if (arity > Definitions .MaxTupleArity ) productElement :: productArity :: Nil
421
- else Nil
422
-
423
418
if (isCaseClass)
424
- largeProductMeths ::: copyMeths ::: enumTagMeths ::: productElemMeths.toList
419
+ productElement :: productArity :: copyMeths ::: enumTagMeths ::: productElemMeths.toList
420
+ else if (isCaseObject)
421
+ productArity :: productElement :: Nil
425
422
else Nil
426
423
}
427
424
428
425
def anyRef = ref(defn.AnyRefAlias .typeRef)
429
- def productConstr (n : Int ) = {
430
- val tycon = scalaDot((str.Product + n).toTypeName)
431
- val targs = constrVparamss.head map (_.tpt)
432
- if (targs.isEmpty) tycon else AppliedTypeTree (tycon, targs)
433
- }
434
- def product =
435
- if (arity > Definitions .MaxTupleArity ) scalaDot(str.Product .toTypeName)
436
- else productConstr(arity)
437
426
438
- // Case classes and case objects get Product/ProductN parents
427
+ // Case classes and case objects get Product parents
439
428
var parents1 = parents
440
429
if (isEnumCase && parents.isEmpty)
441
430
parents1 = enumClassTypeRef :: Nil
442
- if (mods.is( Case ) )
443
- parents1 = parents1 :+ product // TODO: This also adds Product0 to case objects. Do we want that?
431
+ if (isCaseClass | isCaseObject )
432
+ parents1 = parents1 :+ scalaDot(str. Product .toTypeName)
444
433
if (isEnum)
445
434
parents1 = parents1 :+ ref(defn.EnumType )
446
435
@@ -499,7 +488,6 @@ object desugar {
499
488
companionDefs(anyRef, Nil )
500
489
else Nil
501
490
502
-
503
491
// For an implicit class C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, .., pMN: TMN), the method
504
492
// synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] =
505
493
// new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) =
0 commit comments