Skip to content

Commit

Permalink
Support refinement type on enum case
Browse files Browse the repository at this point in the history
This used to fail with:
    trait <refinement> in value x extends enum EC, but extending enums is prohibited.
  • Loading branch information
smarter committed Oct 3, 2024
1 parent c332766 commit afee285
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions tests/pos/enum-refinement.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit afee285

Please sign in to comment.