Skip to content

Commit 361546c

Browse files
authored
Merge pull request #14571 from Xavientois/safe-init-for-case-kind-enum
Fix safe-init error in DesugarEnums
2 parents 29e4b05 + 15ec5b6 commit 361546c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@ import scala.annotation.internal.sharable
1616
object DesugarEnums {
1717
import untpd._
1818

19-
@sharable object CaseKind extends Enumeration {
20-
val Simple, Object, Class: Value = Value
21-
}
19+
enum CaseKind:
20+
case Simple, Object, Class
2221

23-
final case class EnumConstraints(minKind: CaseKind.Value, maxKind: CaseKind.Value, enumCases: List[(Int, RefTree)]):
24-
require(minKind <= maxKind && !(cached && enumCases.isEmpty))
22+
final case class EnumConstraints(minKind: CaseKind, maxKind: CaseKind, enumCases: List[(Int, RefTree)]):
23+
require(minKind.ordinal <= maxKind.ordinal && !(cached && enumCases.isEmpty))
2524
def requiresCreator = minKind == CaseKind.Simple
26-
def isEnumeration = maxKind < CaseKind.Class
27-
def cached = minKind < CaseKind.Class
25+
def isEnumeration = maxKind.ordinal < CaseKind.Class.ordinal
26+
def cached = minKind.ordinal < CaseKind.Class.ordinal
2827
end EnumConstraints
2928

3029
/** Attachment containing the number of enum cases, the smallest kind that was seen so far,
3130
* and a list of all the value cases with their ordinals.
3231
*/
33-
val EnumCaseCount: Property.Key[(Int, CaseKind.Value, CaseKind.Value, List[(Int, TermName)])] = Property.Key()
32+
val EnumCaseCount: Property.Key[(Int, CaseKind, CaseKind, List[(Int, TermName)])] = Property.Key()
3433

3534
/** Attachment signalling that when this definition is desugared, it should add any additional
3635
* lookup methods for enums.
@@ -249,11 +248,11 @@ object DesugarEnums {
249248
* - scaffolding containing the necessary definitions for singleton enum cases
250249
* unless that scaffolding was already generated by a previous call to `nextEnumKind`.
251250
*/
252-
def nextOrdinal(name: Name, kind: CaseKind.Value, definesLookups: Boolean)(using Context): (Int, List[Tree]) = {
251+
def nextOrdinal(name: Name, kind: CaseKind, definesLookups: Boolean)(using Context): (Int, List[Tree]) = {
253252
val (ordinal, seenMinKind, seenMaxKind, seenCases) =
254253
ctx.tree.removeAttachment(EnumCaseCount).getOrElse((0, CaseKind.Class, CaseKind.Simple, Nil))
255-
val minKind = if kind < seenMinKind then kind else seenMinKind
256-
val maxKind = if kind > seenMaxKind then kind else seenMaxKind
254+
val minKind = if kind.ordinal < seenMinKind.ordinal then kind else seenMinKind
255+
val maxKind = if kind.ordinal > seenMaxKind.ordinal then kind else seenMaxKind
257256
val cases = name match
258257
case name: TermName => (ordinal, name) :: seenCases
259258
case _ => seenCases

0 commit comments

Comments
 (0)