icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Better error message for Slice2 enum #575

Closed externl closed 1 year ago

externl commented 1 year ago

Closes #569

error [E011]: invalid enum 'Bar': underlying type 'None' is not supported for enums
 --> foo.slice:3:1
  |
3 | enum Bar {
  | --------
  |
    = note: Slice2 enums must have an underlying type. e.g. 'enum Bar : uint8'
    = note: file is using the Slice2 encoding by default
    = note: to use a different encoding, specify it at the top of the slice file. e.g. 'encoding = Slice1'

Failed: Compilation failed with 1 error(s)
pepone commented 1 year ago

In the original message, we have:

error E011: invalid enum 'MyEnum': underlying type 'None' is not supported for enums

https://github.com/icerpc/slicec/blob/0ff4122207729b0bea05c661a25ff75dd4e5daa5/src/diagnostics/errors.rs#L328-L334

None is a Rust type, but is not a Slice type, I think this needs fixing too

error E0XX: invalid enum 'MyEnum': Slice2 enums must have an underlying type. e.g. 'enum Bar : uint8' and remvoe the Note

I'm not fond of these notes:

= note: file is using the Slice2 encoding by default
= note: to use a different encoding, specify it at the top of the slice file. e.g. 'encoding = Slice1

It is like we suggest going back to Slice1 at every opportunity

externl commented 1 year ago

I think we should suggest "you may want to use Slice1" only when:

  • the user defines a class in a Slice2 file
  • the user references a Slice1-only construct from a Slice2 file (class or other constructed type that is Slice1-only for some reason)

Yes, I've opened a new issue to fix this generally. I'll fix the enum for now.

externl commented 1 year ago

I don't think we should mix the error message and suggestion together. I agree that we should not use none.

externl commented 1 year ago
error [E011]: invalid enum 'Bar': an underlying type is required
 --> foo.slice:3:1
  |
3 | enum Bar {
  | --------
  |
    = note: Slice2 enums must have an underlying type. e.g. 'enum Bar : uint8'

Failed: Compilation failed with 1 error(s)