Skip to content

Commit ef77817

Browse files
committed
support & in mirrorCompanionRef
1 parent 7fbbeef commit ef77817

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

compiler/src/dotty/tools/dotc/transform/TypeUtils.scala

+5
Original file line numberDiff line numberDiff 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 =>

tests/neg/i15190.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

tests/run/i15190.scala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)