icerpc / slicec

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

Associated fields in Enumerator #682

Closed bernardnormier closed 9 months ago

bernardnormier commented 9 months ago

The associated fields of an Enumerator are an:

 pub associated_fields: Option<Vec<WeakPtr<Field>>>,

And apparently, when slicec parses an enumerator, it:

This seems overcomplicated. Why not simply:

 pub associated_fields: Vec<WeakPtr<Field>>,

with an empty vec in the common situation where the enumerator has no associated field.

InsertCreativityHere commented 9 months ago

The reason is to disallow this:

enum Foo: uint8 {
    A()
}

Using field syntax within an enum-with-an-underlying-type. Even though this enum technically doesn't have any fields, it seemed cleaner to me to disallow even the syntax.

If we only stored a Vec, we couldn't distinguish between A and A().

InsertCreativityHere commented 9 months ago

This change was implemented in #685

bernardnormier commented 9 months ago

This change meaning:

Changes fields to return a Vec instead of an Option<Vec> for easier use (None => vec![]).