Scala

Scala

By DeepSource

Enum value has a member that maps to an already mapped value SC-W1087

Bug risk
Critical

An enum holds different members that map to different values. In most languages, it is usually expected that these members map to unique values. However, in this case, one or more members map to a value that was already associated with a different member. This could likely be a mistake and greatly affect your program's logic and behaviour. It is recommended that you review all the values associated with this enum's members.

Bad Practice

enum Constant(d: Double) {
  case E   extends Constant(2.7182)
  case Pi  extends Constant(3.1415)
  case Tau extends Constant(3.1415) // Duplicated value
}

Recommended

enum Constant(d: Double) {
  case E   extends Constant(2.7182)
  case Pi  extends Constant(3.1415)
  case Tau extends Constant(6.2831) // Fixed
}