File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,11 @@ object TypeUtils {
9292 val r2 = tp2.mirrorCompanionRef
9393 assert(r1.symbol == r2.symbol, em " mirrorCompanionRef mismatch for $self: $r1, $r2 did not have the same symbol " )
9494 r1
95+ case AndType (tp1, tp2) =>
96+ val c1 = tp1.classSymbol
97+ val c2 = tp2.classSymbol
98+ if c1.isSubClass(c2) then tp1.mirrorCompanionRef
99+ else tp2.mirrorCompanionRef // precondition: the parts of the AndType have already been checked to be non-overlapping
95100 case self @ TypeRef (prefix, _) if self.symbol.isClass =>
96101 prefix.select(self.symbol.companionModule).asInstanceOf [TermRef ]
97102 case self : TypeProxy =>
Original file line number Diff line number Diff line change 1+ import scala .deriving .Mirror
2+
3+ trait Mixin
4+ object Mixin
5+
6+ trait Parent
7+ object Parent
8+
9+ sealed trait Fruit extends Parent
10+ object Fruit {
11+ case object Apple extends Fruit
12+ case object Orange extends Fruit
13+ }
14+
15+ @ main def Test = {
16+ summon[Mirror .SumOf [Fruit & Mixin ]] // error: not a sum type
17+ }
Original file line number Diff line number Diff line change 1+ import scala .deriving .Mirror
2+
3+ trait Mixin
4+ object Mixin
5+
6+ trait Parent
7+ object Parent
8+
9+ sealed trait Fruit extends Parent
10+ object Fruit {
11+ case object Apple extends Fruit
12+ case object Orange extends Fruit
13+ }
14+
15+ @ main def Test = {
16+ val mFruit = summon[Mirror .SumOf [Fruit & Parent ]]
17+ assert(mFruit.ordinal(Fruit .Apple ) == 0 )
18+ assert(mFruit.ordinal(Fruit .Orange ) == 1 )
19+ }
You can’t perform that action at this time.
0 commit comments