From afee285a2a163c0ee3dafde04b1f3175f1687802 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 3 Oct 2024 14:25:51 +0200 Subject: [PATCH] Support refinement type on enum case This used to fail with: trait in value x extends enum EC, but extending enums is prohibited. --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/pos/enum-refinement.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/pos/enum-refinement.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 159ce8354a30..97373ad9b2bc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -3166,7 +3166,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer .withType(dummy.termRef) if (!cls.isOneOf(AbstractOrTrait) && !ctx.isAfterTyper) checkRealizableBounds(cls, cdef.sourcePos.withSpan(cdef.nameSpan)) - if cls.isEnum || firstParentTpe.classSymbol.isEnum then + if cls.isEnum || !cls.isRefinementClass && firstParentTpe.classSymbol.isEnum then checkEnum(cdef, cls, firstParent) val cdef1 = assignType(cpy.TypeDef(cdef)(name, impl1), cls) diff --git a/tests/pos/enum-refinement.scala b/tests/pos/enum-refinement.scala new file mode 100644 index 000000000000..e357125489cd --- /dev/null +++ b/tests/pos/enum-refinement.scala @@ -0,0 +1,12 @@ +enum Enum: + case EC(val x: Int) + +val a: Enum.EC { val x: 1 } = Enum.EC(1).asInstanceOf[Enum.EC { val x: 1 }] + +import scala.language.experimental.modularity + +enum EnumT: + case EC(tracked val x: Int) + +val b: EnumT.EC { val x: 1 } = EnumT.EC(1) +