robotpy-build icon indicating copy to clipboard operation
robotpy-build copied to clipboard

[BUG]: Tagged Unions

Open JaciBrunning opened this issue 11 months ago • 1 comments
trafficstars

Problem description

Given the following struct:

template<typename T>
struct CGrappleResult {
  enum class Tag {
    Ok,
    Err,
  };

  struct Ok_Body {
    T _0;
  };

  struct Err_Body {
    CGrappleError _0;
  };

  Tag tag;
  union {
    Ok_Body ok;
    Err_Body err;
  };
};

The generator fails to generate the class with "ValueError: not sure how to handle 'union <<id=1>>`

The expected behaviour is to treat it as a tagged union, exposing both variants as class fields and leaving it to the user to discriminate them.

Operating System

Windows

Installed Python Packages

No response

Reproducible example code

No response

JaciBrunning avatar Nov 22 '24 11:11 JaciBrunning

This hasn't come up very much, so I'm inclined to not handle it automatically. You'll need to write your own binding code.

std::variant is a more modern way of implementing this pattern. If you use std::variant instead as your result, that should be supported out of the box.

virtuald avatar Nov 22 '24 16:11 virtuald

I don't think we'll support this.

virtuald avatar May 17 '25 13:05 virtuald