Registry Mirror
Skip to content

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #577.

The bool -> transparent-struct implicit conversion operator wraps the value in a cast ((type)(...)) for backing types other than int/uint, but the else branch in GenerateTransparentStructs emitted only the cast''s closing parenthesis and dropped the one that closes the constructor argument. For a byte;Boolean transparent struct this produced:

public static implicit operator MyBoolean(bool value) => new MyBoolean((byte)(value ? 1u : 0u);

which fails to compile. Now emits the balanced form:

public static implicit operator MyBoolean(bool value) => new MyBoolean((byte)(value ? 1u : 0u));

The int/uint branches were already correct (they don''t add the extra cast wrapper).

Also adds a regression test exercising the generate-helper-types boolean transparent struct emission -- this path had no golden coverage previously, which is how the bug shipped. Full suite: 3709 passing (existing 3708 byte-identical), build 0/0.

Note

This PR description was drafted by Copilot on my behalf.

…n conversion

The bool-to-transparent-struct implicit operator wrapped the value in a cast for types other than int/uint but emitted only the cast's closing parenthesis, dropping the one that closes the constructor argument. This produced code like new MyBoolean((byte)(value ? 1u : 0u); which fails to compile. Adds the missing parenthesis and a regression test covering the generate-helper-types boolean transparent struct emission, which previously had no golden coverage.

Fixes dotnet#577

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Generating a transparent struct of a boolean byte generates C# code with a missing parenthesis

1 participant