@@ -439,14 +439,15 @@ trait CaseClassMacros extends ReprTypes with CaseClassMacrosVersionSpecifics {
439
439
fn1 < fn2 || (fn1 == fn2 && isLess(s1, s2))
440
440
}
441
441
442
- val ctorSyms = collectCtors(baseSym).sortWith(orderSyms)
443
- val ctors =
444
- ctorSyms flatMap { sym =>
445
- import c .internal ._
442
+ val ctors = collectCtors(baseSym).sortWith(orderSyms).flatMap { sym =>
443
+ import c .internal ._
446
444
445
+ val owner = sym.owner
446
+ val isNamed = ! isAnonOrRefinement(sym)
447
+
448
+ // Construct a stable prefix from the path.
449
+ val pre = if (sym.isStatic) prefix(sym.toType) else {
447
450
// Look for a path from the macro call site to the subtype.
448
- val owner = sym.owner
449
- val isNamed = ! isAnonOrRefinement(sym)
450
451
val owners = ownerChain(if (isNamed) owner else owner.owner)
451
452
val prePaths = for (pre <- Iterator .iterate(basePre)(prefix).takeWhile(_ != NoPrefix ))
452
453
yield (pre, owners.iterator.dropWhile(pre.baseType(_) == NoType ))
@@ -458,44 +459,43 @@ trait CaseClassMacros extends ReprTypes with CaseClassMacrosVersionSpecifics {
458
459
(NoPrefix , if (common < 0 ) Iterator .empty else owners.iterator drop common - 1 )
459
460
}
460
461
461
- // Construct a stable prefix from the path.
462
- val pre = path.drop(1 ).foldLeft(pre0) { (pre1, part) =>
462
+ path.drop(1 ).foldLeft(pre0) { (pre1, part) =>
463
463
if (part.isType) part.asType.toTypeIn(pre1)
464
464
else abort(s " $tpe has a subtype $sym with unstable prefix " )
465
465
}
466
+ }
466
467
467
- val ctor = if (isNamed) {
468
- if (sym.isModuleClass) {
469
- sym.toTypeIn(pre)
470
- } else {
471
- val subst = thisType(sym).baseType(baseSym).typeArgs
472
- val params = sym.typeParams
473
- val (args, free) = params.foldRight((List .empty[Type ], false )) {
474
- case (param, (args, free)) =>
475
- val i = subst.indexWhere(_.typeSymbol == param)
476
- val arg = if (i >= 0 ) baseArgs(i) else param.asType.toType
477
- (arg :: args, free || i < 0 )
478
- }
479
-
480
- val ref = typeRef(pre, sym, args)
481
- if (free) existentialAbstraction(params, ref) else ref
482
- }
468
+ val ctor = if (isNamed) {
469
+ if (sym.isModuleClass) {
470
+ sym.toTypeIn(pre)
483
471
} else {
484
- def ownerIsSubType = owner.typeSignatureIn(pre) <:< baseTpe
485
- if (owner.isTerm && owner.asTerm.isVal && ownerIsSubType) singleType(pre, owner)
486
- else abort(s " $tpe has a subtype $sym with unstable prefix " )
487
- }
472
+ val subst = thisType(sym).baseType(baseSym).typeArgs.map(_.typeSymbol)
473
+ val params = sym.typeParams
474
+ val free = params.exists(! subst.contains(_))
475
+ val args = for (param <- params) yield {
476
+ val i = subst.indexOf(param)
477
+ if (i >= 0 ) baseArgs(i) else param.asType.toType
478
+ }
488
479
489
- if (! isAccessible(ctor))
490
- abort(s " $tpe has an inaccessible subtype $ctor" )
491
- if (ctor <:< baseTpe) Some (ctor) else None
480
+ val ref = typeRef(pre, sym, args)
481
+ if (free) existentialAbstraction(params, ref) else ref
482
+ }
483
+ } else {
484
+ def ownerIsSubType = owner.typeSignatureIn(pre) <:< baseTpe
485
+ if (owner.isTerm && owner.asTerm.isVal && ownerIsSubType) singleType(pre, owner)
486
+ else abort(s " $tpe has a subtype $sym with unstable prefix " )
492
487
}
493
- if (ctors.isEmpty)
494
- abort(s " Sealed trait $tpe has no case class subtypes " )
495
- ctors
496
- }
497
- else
488
+
489
+ if (! isAccessible(ctor)) abort(s " $tpe has an inaccessible subtype $ctor" )
490
+ else if (ctor <:< baseTpe) Some (ctor)
491
+ else None
492
+ }
493
+
494
+ if (ctors.isEmpty) abort(s " Sealed trait $tpe has no case class subtypes " )
495
+ else ctors
496
+ } else {
498
497
abort(s " $tpe is not a case class, case class-like, a sealed trait or Unit " )
498
+ }
499
499
}
500
500
501
501
def nameAsString (name : Name ): String = name.decodedName.toString.trim
0 commit comments