Skip to content

Better error message when an enum extends AnyVal #21944

Closed
@hamzaremmal

Description

@hamzaremmal

Compiler version

bed0e86

Minimized example

enum Orientation extends AnyVal:
    case North, South, East, West

Output Error/Warning message

-- [E074] Syntax Error: t.scala:2:5 --------------------------------------------
2 |enum Orientation extends AnyVal:
  |     ^
  |     Value classes may not be abstract
-- [E093] Syntax Error: t.scala:3:29 -------------------------------------------
3 |    case North, South, East, West
  |                             ^
  |               anonymous class {...} cannot extend final class Orientation
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | A class marked with the final keyword cannot be extended
   -----------------------------------------------------------------------------

Why this Error/Warning was not helpful

The message leaks implementation details about desugaring...

Suggested improvement

A message saying that enums cannot extend AnyVal is better here

Metadata

Metadata

Assignees

Labels

SpreeSuitable for a future Spreearea:desugarDesugaring happens after parsing but before typing, see desugar.scalaarea:enumsarea:reportingError reporting including formatting, implicit suggestions, etcarea:value-classesIssues tied to value classes.better-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions