mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #24021 The field checking for case object branches at some point generates a negated set `contains` check for the object discriminator. For enum types, this tries to generate a complement set and convert to a `contains` check in that instead. It obtains this type from the type of the element node in the `contains` check. `buildProperFieldCheck` creates the element node by changing a field access expression like `foo.z` into `foo.kind`. In order to do this, it copies the node `foo.z` and sets the field name in the node to the symbol `kind`. But when copying the node, the type of the original `foo.z` is retained. This means that the complement is performed on the type of the accessed field rather than the type of the discriminator, which causes problems when the accessed field is also an enum. To fix this, we properly set the type of the copied node to the type of the kind field. An alternative is just to make a new node instead. A lot of text for a single line change, I know, but this part of the codebase could use more explanation.