Document how to change base type of an enum
- ~Add
TypeNode.base_typeforEnumtypes~ - ~Add
Enum.base_typethat uses the macro method~ - Mention the ability to change the base type in the
EnumAPI docs
Umm, not sure why specs failed. They passed locally for me. Some caching issue?
std specs also run with the current compiler, and base_type is not defined there. You can implement it by doing typeof(values.first)
~@asterite But how are all the other macro methods useable? {% if @type.has_attribute?("Flags") %} is a TypeNode method and that doesn't cause things to break.~
EDIT: NVM, I misread. I suppose, but think this macro method would be most ideal :/. Maybe I'll add a todo to update it after the next release.
Can you show a use case for this? typeof(value) already works to determine the base type. So this is essentially just adding a dedicated method for this? Where is this needed?
@straight-shoota It originally came from some chat in Gitter. https://gitter.im/crystal-lang/crystal?at=5f7afbbc6e0eb8446967c41e
I'd maybe ask @HertzDevil what he was doing it for. But IMO, there should be a better API for getting that type than doing a typeof of one of the values given it's known at compile time anyway.
Unless there's a common use case I'd say type(value) is totally fine. No need for adding an extra part to the API. typeof is evaluated at compile time, so there's no runtime impact.
Will leave it up to @HertzDevil then. If he doesn't have any specific use cases then I'm fine with closing, or at least revert the new method and keep the doc updates.
I kinda forgot about this, but I just reverted the methods and just made this document how to change the base type of an enum.