mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
internal/order: fix sorting of synthetic oneofs to be deterministic
Before this change, synthetic oneofs were ignored in the inOneof() helper function, but not in the remainder of the LegacyFieldOrder function. Change-Id: Ia60e5244ae1000e98bbba9dd26f1d1583337fab4 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/497935 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Lasse Folger <lassefolger@google.com> Reviewed-by: Cassondra Foesch <cfoesch@gmail.com>
This commit is contained in:
parent
b8fc770601
commit
cc524c9cf1
@ -33,7 +33,7 @@ var (
|
||||
return !inOneof(ox) && inOneof(oy)
|
||||
}
|
||||
// Fields in disjoint oneof sets are sorted by declaration index.
|
||||
if ox != nil && oy != nil && ox != oy {
|
||||
if inOneof(ox) && inOneof(oy) && ox != oy {
|
||||
return ox.Index() < oy.Index()
|
||||
}
|
||||
// Fields sorted by field number.
|
||||
|
@ -65,9 +65,9 @@ func TestFieldOrder(t *testing.T) {
|
||||
// Non-extension fields that are not within a oneof
|
||||
// sorted next by field number.
|
||||
{number: 1},
|
||||
{number: 5, oneofIndex: -9}, // synthetic oneof
|
||||
{number: 5, oneofIndex: -10}, // synthetic oneof
|
||||
{number: 10},
|
||||
{number: 11, oneofIndex: -10}, // synthetic oneof
|
||||
{number: 11, oneofIndex: -9}, // synthetic oneof
|
||||
{number: 12},
|
||||
|
||||
// Non-synthetic oneofs sorted last by index.
|
||||
|
Loading…
Reference in New Issue
Block a user