Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Tagged Unions #239

Open
JaciBrunning opened this issue Nov 22, 2024 · 1 comment
Open

[BUG]: Tagged Unions #239

JaciBrunning opened this issue Nov 22, 2024 · 1 comment

Comments

@JaciBrunning
Copy link

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

@virtuald virtuald changed the title [BUG]: Anonymous Unions fail to Generate [BUG]: Tagged Unions Nov 22, 2024
@virtuald
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants