Skip to content

Commit

Permalink
all: implement features.field_presence = LEGACY_REQUIRED support
Browse files Browse the repository at this point in the history
Change-Id: Iaba3f4b81ac1b73f7542397a479642d081152c39
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/565656
Auto-Submit: Lasse Folger <[email protected]>
Reviewed-by: Michael Stapelberg <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
lfolger authored and gopherbot committed Feb 21, 2024
1 parent 6e0d73f commit 7d98b0e
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 89 deletions.
3 changes: 3 additions & 0 deletions internal/filedesc/desc_lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ func (fd *Field) unmarshalFull(b []byte, sb *strs.Builder, pf *File, pd protoref
if fd.Syntax() == protoreflect.Editions && fd.L1.Kind == protoreflect.MessageKind && fd.L1.EditionFeatures.IsDelimitedEncoded {
fd.L1.Kind = protoreflect.GroupKind
}
if fd.Syntax() == protoreflect.Editions && fd.L1.EditionFeatures.IsLegacyRequired {
fd.L1.Cardinality = protoreflect.Required
}
if rawTypeName != nil {
name := makeFullName(sb, rawTypeName)
switch fd.L1.Kind {
Expand Down
352 changes: 280 additions & 72 deletions internal/testprotos/testeditions/test.pb.go

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions internal/testprotos/testeditions/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,16 @@ enum ForeignEnum {
FOREIGN_BAR = 5;
FOREIGN_BAZ = 6;
}

message TestRequired {
int32 required_field = 1 [features.field_presence = LEGACY_REQUIRED];
}

message TestRequiredForeign {
TestRequired optional_message = 1;
repeated TestRequired repeated_message = 2;
map<int32, TestRequired> map_message = 3;
oneof oneof_field {
TestRequired oneof_message = 4;
}
}
73 changes: 56 additions & 17 deletions internal/testprotos/testeditions/test_extension.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/testprotos/testeditions/test_extension.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ message RepeatedGroup {
int32 a = 47;
TestAllExtensions.NestedMessage optional_nested_message = 1001;
}

extend TestAllExtensions {
TestRequired single = 1000;
repeated TestRequired multi = 1001;
}
24 changes: 24 additions & 0 deletions proto/checkinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

testpb "google.golang.org/protobuf/internal/testprotos/test"
weakpb "google.golang.org/protobuf/internal/testprotos/test/weak1"
testeditionspb "google.golang.org/protobuf/internal/testprotos/testeditions"
)

func TestCheckInitializedErrors(t *testing.T) {
Expand Down Expand Up @@ -46,6 +47,29 @@ func TestCheckInitializedErrors(t *testing.T) {
},
},
want: `goproto.proto.test.TestRequired.required_field`,
}, {
m: &testeditionspb.TestRequired{},
want: `goproto.proto.testeditions.TestRequired.required_field`,
}, {
m: &testeditionspb.TestRequiredForeign{
OptionalMessage: &testeditionspb.TestRequired{},
},
want: `goproto.proto.testeditions.TestRequired.required_field`,
}, {
m: &testeditionspb.TestRequiredForeign{
RepeatedMessage: []*testeditionspb.TestRequired{
{RequiredField: proto.Int32(1)},
{},
},
},
want: `goproto.proto.testeditions.TestRequired.required_field`,
}, {
m: &testeditionspb.TestRequiredForeign{
MapMessage: map[int32]*testeditionspb.TestRequired{
1: {},
},
},
want: `goproto.proto.testeditions.TestRequired.required_field`,
}, {
m: &testpb.TestWeak{},
want: `<nil>`,
Expand Down

0 comments on commit 7d98b0e

Please sign in to comment.