Skip to content

Conversation

@zhangw
Copy link

@zhangw zhangw commented Apr 26, 2025

Before the fix, the generated bitset-related code looked like this:

type PresenceMapChoiceValue uint8
type PresenceMapChoiceValues struct {
FooField PresenceMapChoiceValue
BarField PresenceMapChoiceValue
}
var PresenceMapChoice = PresenceMapChoiceValues{uint64(0), uint64(1)}

This caused a compile error:
cannot use uint64(0) (constant 0 of type uint64) as PresenceMapChoiceValue value in struct literal
compilerIncompatibleAssign

The issue is that uint64(0) cannot be directly assigned to a field of type PresenceMapChoiceValue (uint8 alias).

After the fix, the generated code is:
var PresenceMapChoice = PresenceMapChoiceValues{0, 1}

This is simple, correct, and compiles without the issues before.

@vyazelenko
Copy link
Contributor

@zhangw Please add a test for this fix.

@vyazelenko vyazelenko changed the title Fix compile issue in generated bitset XXChoiceValues struct [Go] Fix compile issue in generated bitset XXChoiceValues struct Jun 11, 2025
@vyazelenko
Copy link
Contributor

@zhangw We have example-schema.xml that contains a set definition:

<set name="OptionalExtras" encodingType="uint8">
    <choice name="sunRoof">0</choice>
    <choice name="sportsPack">1</choice>
    <choice name="cruiseControl">2</choice>
</set>

And the code generated for it when you run ./gradlew generateGolangCodecs (check gocode/struct/src/extension/OptionalExtras.go):

type OptionalExtrasChoiceValue uint8
type OptionalExtrasChoiceValues struct {
	SunRoof       OptionalExtrasChoiceValue
	SportsPack    OptionalExtrasChoiceValue
	CruiseControl OptionalExtrasChoiceValue
}

var OptionalExtrasChoice = OptionalExtrasChoiceValues{0, 1, 2}

@vyazelenko vyazelenko closed this Jun 12, 2025
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.

2 participants