Skip to content

Commit e80dcba

Browse files
committed
add checks for HK and annots
1 parent 74eeebd commit e80dcba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
274274
val useCompanion = cls.useCompanionAsSumMirror
275275

276276
def acceptable(tp: Type): Boolean = tp match
277+
case tp: TermRef => false
278+
case tp: TypeProxy => acceptable(tp.underlying)
277279
case OrType(tp1, tp2) => acceptable(tp1) && acceptable(tp2)
278-
case _ => !tp.termSymbol.isEnumCase && (tp.classSymbol eq cls)
280+
case _ => tp.classSymbol eq cls
279281

280282
if acceptable(mirroredType) && cls.isGenericSum(if useCompanion then cls.linkedClass else ctx.owner) then
281283
val elemLabels = cls.children.map(c => ConstantType(Constant(c.name.toString)))

tests/neg/scala_enum_testing.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ object Singletons {
1616
object B
1717
}
1818

19+
type SumOfK1[F[_]] = Mirror.Sum { type MirroredType[T] = F[T] }
20+
21+
class refined extends scala.annotation.RefiningAnnotation
22+
1923
object Test {
2024

2125
def main(args: Array[String]): Unit = {
@@ -24,5 +28,13 @@ object Test {
2428
summon[Mirror.SumOf[Color.Red.type | Color.Green.type]] // error
2529
summon[Mirror.SumOf[Bar.A | Bar.B]] // error
2630
summon[Mirror.SumOf[Singletons.A.type | Singletons.B.type]] // error
31+
summon[SumOfK1[[X] =>> Bar]]
32+
summon[SumOfK1[[X] =>> Bar.A | Bar.B]] // error
33+
summon[SumOfK1[[X] =>> (Bar.A | Bar.B) @refined]] // error
34+
object opaques {
35+
opaque type Query[X] = (Bar.A | Bar.B) @refined
36+
}
37+
summon[SumOfK1[opaques.Query]] // error
38+
summon[SumOfK1[[X] =>> (Bar.A @refined) | Bar.B]] // error
2739
}
2840
}

0 commit comments

Comments
 (0)