icerpc/slicec

Poor errors for Slice1 enum

Closed this issue · 2 comments

If you attempt to define an enum with an underlying type or associated field in Slice1, you should get an error like "underlying type not valid for Slice1 enum" and "associated field not available in Slice1 mode".

But you get instead the same perplexing error:

error E029: enum 'TestEnum1' cannot be defined in Slice1 mode

This is a limitation of the builder, not slicec. slicec will always tell you exactly what the problem is, either:

error E029: enum 'TestEnum1' cannot be defined in Slice1 mode
enums defined in Slice1 mode cannot have underlying types

or

error E029: enum 'TestEnum1' cannot be defined in Slice1 mode
enumerators declared in Slice1 mode cannot have associated fields

But, the builder doesn't display the full diagnostic.
Try running slicec directly from the command line for the file in question to see the full diagnostic it emits.

pepone commented

The MSBuild builder also shows the additional notes:

C:\Users\jose\source\repos\MySliceClient\slice\Greeter.slice(6,1,6,9): error E029: enum 'Foo' cannot be defined in Slice1 mode [C:\Users\jose\source\repos\MySliceClient\MySliceClient.csproj]
C:\Users\jose\source\repos\MySliceClient\slice\Greeter.slice(6,1,6,9): message : enums defined in Slice1 mode cannot have underlying types [C:\Users\jose\source\repos\MySliceClient\MySliceClient.csproj]

Additional messages are logged separately; see here.

We considered concatenating the notes to the main error message. However, we decided against it because notes can have different locations, which would be lost. This is relevant in cases of redefinitions.