reflect/protodesc: add missing IsProto3Optional initialization

Initialization of L2 is symmetric: there is the filedesc initialization
in internal/filedesc/desc_lazy.go and the protodesc initialization
in reflect/protodesc/desc_init.go.

The IsProto3Optional field was only initialized in filedesc/desc_lazy.go.

Fixes golang/protobuf#1709

Change-Id: I0d6b6afa2d495c023b451c68f902543f2611844c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/737480
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
diff --git a/reflect/protodesc/desc_init.go b/reflect/protodesc/desc_init.go
index c826ad0..84a3228 100644
--- a/reflect/protodesc/desc_init.go
+++ b/reflect/protodesc/desc_init.go
@@ -201,6 +201,7 @@
 			return nil, err
 		}
 		x.L1.EditionFeatures = mergeEditionFeatures(parent, xd.GetOptions().GetFeatures())
+		x.L2.IsProto3Optional = xd.GetProto3Optional()
 		if opts := xd.GetOptions(); opts != nil {
 			opts = proto.Clone(opts).(*descriptorpb.FieldOptions)
 			x.L2.Options = func() protoreflect.ProtoMessage { return opts }
diff --git a/reflect/protodesc/file_test.go b/reflect/protodesc/file_test.go
index e699d01..c38d5da 100644
--- a/reflect/protodesc/file_test.go
+++ b/reflect/protodesc/file_test.go
@@ -958,6 +958,46 @@
 	}
 }
 
+func TestNewFileProto3OptionalExt(t *testing.T) {
+	fdset := &descriptorpb.FileDescriptorSet{
+		File: []*descriptorpb.FileDescriptorProto{
+			mustParseFile(`
+				name: "google/protobuf/descriptor.proto"
+				package: "google.protobuf"
+				message_type: [{
+					name: "EnumValueOptions"
+					extension_range: [{start:1 end:536870912}]
+				}]
+			`),
+			mustParseFile(`
+				syntax: "proto3"
+				name: "test.proto"
+				package: "test"
+				dependency: "google/protobuf/descriptor.proto"
+				extension: [{
+					name: "optional_field"
+					number: 100000
+					label: LABEL_OPTIONAL
+					type: TYPE_STRING
+					extendee: ".google.protobuf.EnumValueOptions"
+					proto3_optional: true
+				}]
+			`),
+		},
+	}
+	f, err := NewFiles(fdset)
+	if err != nil {
+		t.Fatalf("NewFile(test.proto): %v", err)
+	}
+	ext, err := f.FindDescriptorByName("test.optional_field")
+	if err != nil {
+		t.Fatalf(`f.FindDescriptorByName("test.optional_field") = %v`, err)
+	}
+	if !ext.(protoreflect.ExtensionDescriptor).HasOptionalKeyword() {
+		t.Errorf("HasOptionalKeyword() = false, want true for proto3 optional extension field")
+	}
+}
+
 func TestNewFiles(t *testing.T) {
 	fdset := &descriptorpb.FileDescriptorSet{
 		File: []*descriptorpb.FileDescriptorProto{