WebAssembly / component-model

Repository for design and specification of the Component Model
Other
914 stars 78 forks source link

Propose `enum` be a subtype of `flags`. #233

Closed sunfishcode closed 10 months ago

sunfishcode commented 11 months ago

I was exploring some hypothetical use cases where it'd be nice to migrate from an enum, "pick one of these", to a flags, "pick any number of these".

For example given these types:

enum berry-enum {
   blueberry,
   strawberry,
   raspberry,
}

flags berry-flags {
   blueberry,
   strawberry,
   raspberry,
}

The proposal is berry-enum <: berry-flags.

I know that the subtyping rules aren't currently a focus, and that they may change when the time does come to focus on them, but I wanted to add this idea to the list so that it's considered.

lukewagner commented 11 months ago

That's an interesting idea, let's tag it as an enhancement and consider it when we're defining/implementing value-level subtyping properly. As #229 suggests, in a preview2 timeframe, we're starting without any value-level subtyping, so probably we'll want to consider in detail the forms of subtyping we do want to allow as a post-preview2 batch.

lukewagner commented 10 months ago

I'll close for now, since subtyping is generally removed from the C-M repo (#255), but we can revisit when we properly treat subtyping in the future. (Feel free to file a new issue to document the idea that we can tag appropriately.)