scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.89k stars 1.06k forks source link

Better error message when an enum extends AnyVal #21944

Open hamzaremmal opened 1 week ago

hamzaremmal commented 1 week ago

Compiler version

https://github.com/scala/scala3/commit/bed0e86180b8e1d83547e99a8ac28efe13cca6c6

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