Skip to content

Commit

Permalink
Do not access enum symbol in DesugarEnums
Browse files Browse the repository at this point in the history
Follow up of scala#19182. Using `fullName` causes the the `parallelBackend`
tests to loop forever.

Fixes scala#19285
Fixes scala#19281
Fixes scala#19278
  • Loading branch information
nicolasstucki committed Dec 18, 2023
1 parent 69cc6b1 commit 0ecbcfb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ object DesugarEnums {

val valuesOfBody: Tree =
val defaultCase =
val msg = Apply(Select(Literal(Constant(s"enum ${enumClass.fullName} has no case with name: ")), nme.PLUS), Ident(nme.nameDollar))
val msg = Apply(Select(Literal(Constant(i"enum $rawEnumClassRef has no case with name: ")), nme.PLUS), Ident(nme.nameDollar))
CaseDef(Ident(nme.WILDCARD), EmptyTree,
Throw(New(TypeTree(defn.IllegalArgumentExceptionType), List(msg :: Nil))))
val stringCases = enumValues.map(enumValue =>
Expand All @@ -143,12 +143,13 @@ object DesugarEnums {
}

private def enumLookupMethods(constraints: EnumConstraints)(using Context): List[Tree] =
val rawEnumClassRef = rawRef(enumClass.typeRef)
def scaffolding: List[Tree] =
if constraints.isEnumeration then enumScaffolding(constraints.enumCases.map(_._2)) else Nil
def valueCtor: List[Tree] = if constraints.requiresCreator then enumValueCreator :: Nil else Nil
def fromOrdinal: Tree =
def throwArg(ordinal: Tree) =
val msg = Apply(Select(Literal(Constant(s"enum ${enumClass.fullName} has no case with ordinal: ")), nme.PLUS), Select(ordinal, nme.toString_))
val msg = Apply(Select(Literal(Constant(i"enum $rawEnumClassRef has no case with ordinal: ")), nme.PLUS), Select(ordinal, nme.toString_))
Throw(New(TypeTree(defn.NoSuchElementExceptionType), List(msg :: Nil)))
if !constraints.cached then
fromOrdinalMeth(throwArg)
Expand Down

0 comments on commit 0ecbcfb

Please sign in to comment.