Skip to content

Commit 7be13eb

Browse files
committed
Revert "Improve failure message of enum fromOrdinal/valueOf"
This reverts commit 2dcd64a. This caused the `parallelBackend` tests to loop forever. Fixes #19285 Fixes #19281 Fixes #19278
1 parent 69cc6b1 commit 7be13eb

File tree

6 files changed

+5
-24
lines changed

6 files changed

+5
-24
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ object DesugarEnums {
126126

127127
val valuesOfBody: Tree =
128128
val defaultCase =
129-
val msg = Apply(Select(Literal(Constant(s"enum ${enumClass.fullName} has no case with name: ")), nme.PLUS), Ident(nme.nameDollar))
129+
val msg = Apply(Select(Literal(Constant("enum case not found: ")), nme.PLUS), Ident(nme.nameDollar))
130130
CaseDef(Ident(nme.WILDCARD), EmptyTree,
131131
Throw(New(TypeTree(defn.IllegalArgumentExceptionType), List(msg :: Nil))))
132132
val stringCases = enumValues.map(enumValue =>
@@ -148,8 +148,7 @@ object DesugarEnums {
148148
def valueCtor: List[Tree] = if constraints.requiresCreator then enumValueCreator :: Nil else Nil
149149
def fromOrdinal: Tree =
150150
def throwArg(ordinal: Tree) =
151-
val msg = Apply(Select(Literal(Constant(s"enum ${enumClass.fullName} has no case with ordinal: ")), nme.PLUS), Select(ordinal, nme.toString_))
152-
Throw(New(TypeTree(defn.NoSuchElementExceptionType), List(msg :: Nil)))
151+
Throw(New(TypeTree(defn.NoSuchElementExceptionType), List(Select(ordinal, nme.toString_) :: Nil)))
153152
if !constraints.cached then
154153
fromOrdinalMeth(throwArg)
155154
else

tests/run/enum-java.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ MONDAY : 0
2626
TUESDAY : 1
2727
SATURDAY : 2
2828
By-name value: MONDAY
29-
Correctly failed to retrieve illegal name, message: enum A has no case with name: stuff
29+
Correctly failed to retrieve illegal name, message: enum case not found: stuff
3030

3131
Collections Test
3232
Retrieving Monday: workday

tests/run/enum-values.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ enum ClassOnly: // this should still generate the `ordinal` and `fromOrdinal` co
6161
catch
6262
case e: java.lang.reflect.InvocationTargetException => // TODO: maybe reflect.Selectable should catch this?
6363
assert(e.getCause.isInstanceOf[java.util.NoSuchElementException]
64-
&& e.getCause.getMessage == s"enum ${companion.getClass.getName.stripSuffix("$")} has no case with ordinal: $ordinal")
64+
&& e.getCause.getMessage == ordinal.toString)
6565

6666
fetchFromOrdinal(companion = Color, compare = Red, Green, Blue)
6767
fetchFromOrdinal(companion = Suits, compare = Clubs, Spades, Diamonds, Hearts)

tests/run/enums-java-compat.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ TUESDAY : 1
66
SATURDAY : 2
77
Stuff : 3
88
By-name value: MONDAY
9-
Correctly failed to retrieve illegal name, message: enum A has no case with name: stuff
9+
Correctly failed to retrieve illegal name, message: enum case not found: stuff

tests/run/i19178.check

-4
This file was deleted.

tests/run/i19178.scala

-14
This file was deleted.

0 commit comments

Comments
 (0)