arik-so / ldk-parser

0 stars 2 forks source link

Make primitive (standalone) enums' variant detection panic instead of using default for the last value #36

Closed arik-so closed 1 year ago

arik-so commented 1 year ago

Same way as we do it for the tagging enum variants in TaggedValueTypes/ComplexEnums.

tnull commented 1 year ago

Mh, I'm not entirely sure what you are referring to with 'default for the last value' here? I assume the general context is this part of the parser code?

https://github.com/arik-so/ldk-parser/blob/25cfb1b7333aacb88e207fe7716a719b6e91e24a/src/parser.mts#L310-L316

arik-so commented 1 year ago

Nope, not quite. Look how the type determination happens in a complex enum, such as APIError:

https://github.com/arik-so/ldk-parser/blob/25cfb1b7333aacb88e207fe7716a719b6e91e24a/out/enums/complex/APIError.swift#L84-L109

Now, compare that to the instantiation of a primitive enum from the C type:

https://github.com/arik-so/ldk-parser/blob/25cfb1b7333aacb88e207fe7716a719b6e91e24a/out/enums/primitive/AccessError.swift#L22-L32.

Basically, the idea is that for primitive enums, there should also not be a default case, but an explicit check, with the default being an abort.

arik-so commented 1 year ago

Perhaps the unsupported value should also be part of the error output in both cases.

arik-so commented 1 year ago

For the generation aspect of it, compare (correct) https://github.com/arik-so/ldk-parser/blob/25cfb1b7333aacb88e207fe7716a719b6e91e24a/src/generation/complex_enum_generator.mts#L34-L52 with (incorrect) https://github.com/arik-so/ldk-parser/blob/25cfb1b7333aacb88e207fe7716a719b6e91e24a/src/generation/primitive_enum_generator.mts#L21-L45