Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #19182: "Improve failure message of enum fromOrdinal/valueOf" #19290

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 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("enum case not found: ")), 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 @@ -148,8 +148,7 @@ object DesugarEnums {
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_))
Throw(New(TypeTree(defn.NoSuchElementExceptionType), List(msg :: Nil)))
Throw(New(TypeTree(defn.NoSuchElementExceptionType), List(Select(ordinal, nme.toString_) :: Nil)))
if !constraints.cached then
fromOrdinalMeth(throwArg)
else
Expand Down
2 changes: 1 addition & 1 deletion tests/run/enum-java.check
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MONDAY : 0
TUESDAY : 1
SATURDAY : 2
By-name value: MONDAY
Correctly failed to retrieve illegal name, message: enum A has no case with name: stuff
Correctly failed to retrieve illegal name, message: enum case not found: stuff

Collections Test
Retrieving Monday: workday
Expand Down
2 changes: 1 addition & 1 deletion tests/run/enum-values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum ClassOnly: // this should still generate the `ordinal` and `fromOrdinal` co
catch
case e: java.lang.reflect.InvocationTargetException => // TODO: maybe reflect.Selectable should catch this?
assert(e.getCause.isInstanceOf[java.util.NoSuchElementException]
&& e.getCause.getMessage == s"enum ${companion.getClass.getName.stripSuffix("$")} has no case with ordinal: $ordinal")
&& e.getCause.getMessage == ordinal.toString)

fetchFromOrdinal(companion = Color, compare = Red, Green, Blue)
fetchFromOrdinal(companion = Suits, compare = Clubs, Spades, Diamonds, Hearts)
Expand Down
2 changes: 1 addition & 1 deletion tests/run/enums-java-compat.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ TUESDAY : 1
SATURDAY : 2
Stuff : 3
By-name value: MONDAY
Correctly failed to retrieve illegal name, message: enum A has no case with name: stuff
Correctly failed to retrieve illegal name, message: enum case not found: stuff
4 changes: 0 additions & 4 deletions tests/run/i19178.check

This file was deleted.

14 changes: 0 additions & 14 deletions tests/run/i19178.scala

This file was deleted.

Loading