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

Fix code generation for nested unions. #44

Merged
merged 1 commit into from
May 10, 2021

Conversation

detly
Copy link
Collaborator

@detly detly commented Jan 14, 2021

When a union is nested inside another union, it must be enclosed in a struct so that its "which" member is not overlapping with its other members.

Schema in question:

struct A {
    union {
        zero @0 :Void;
        one :union {
            first @1 :Void;
            second @2 :UInt16;
        }
    }
}

C code showing bug:

struct A {
	enum A_which which;
	capnp_nowarn union {
		enum A_one_which one_which;
		capnp_nowarn union {
			uint16_t second;
		} one;
	};
};

Correct C code:

struct A {
	enum A_which which;
	capnp_nowarn union {
		capnp_nowarn struct {
			enum A_one_which which;
			capnp_nowarn union {
				uint16_t second;
			};
		} one;
	};
};

Fixes #43.

When a union is nested inside another union, it must be enclosed in a struct
so that its "which" member is not overlapping with its other members.
@detly detly merged commit b619a87 into opensourcerouting:master May 10, 2021
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

Successfully merging this pull request may close these issues.

Nested unions generate incorrect code
1 participant