Skip to content

Enum implementation overrides custom toString #7227

Closed
@cronokirby

Description

@cronokirby

When overriding toStringin an enum, simple cases end up using their name instead of this new implementation.

minimized code

enum E:
  case A
  override def toString: String = "overriden"

println(E.A)

expectation

overriden

result

A

Note that adding an argument to that enum case will return the right result again:

enum E:
  case A(arg: Unit)
  override def toString: String = "overriden"

println(E.A)

This prints overriden as expected.

This has something to do with the desugaring of enums, and the generation of a default toString method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions