Fix latent bug in upb editions implementation caught by python conformance tests.

PiperOrigin-RevId: 619244115
pull/16310/head
Mike Kruskal 11 months ago committed by Copybara-Service
parent e2d0a9e2a4
commit 11e767a899
  1. 34
      upb/reflection/field_def.c

@ -110,15 +110,7 @@ upb_CType upb_FieldDef_CType(const upb_FieldDef* f) {
return upb_FieldType_CType(f->type_);
}
upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) {
// TODO: remove once we can deprecate kUpb_FieldType_Group.
if (f->type_ == kUpb_FieldType_Message &&
UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) ==
UPB_DESC(FeatureSet_DELIMITED)) {
return kUpb_FieldType_Group;
}
return f->type_;
}
upb_FieldType upb_FieldDef_Type(const upb_FieldDef* f) { return f->type_; }
uint32_t upb_FieldDef_Index(const upb_FieldDef* f) { return f->index_; }
@ -126,14 +118,7 @@ uint32_t upb_FieldDef_LayoutIndex(const upb_FieldDef* f) {
return f->layout_index;
}
upb_Label upb_FieldDef_Label(const upb_FieldDef* f) {
// TODO: remove once we can deprecate kUpb_Label_Required.
if (UPB_DESC(FeatureSet_field_presence)(f->resolved_features) ==
UPB_DESC(FeatureSet_LEGACY_REQUIRED)) {
return kUpb_Label_Required;
}
return f->label_;
}
upb_Label upb_FieldDef_Label(const upb_FieldDef* f) { return f->label_; }
uint32_t upb_FieldDef_Number(const upb_FieldDef* f) { return f->number_; }
@ -596,7 +581,6 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
const upb_StringView name = UPB_DESC(FieldDescriptorProto_name)(field_proto);
f->full_name = _upb_DefBuilder_MakeFullName(ctx, prefix, name);
f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
f->number_ = UPB_DESC(FieldDescriptorProto_number)(field_proto);
f->is_proto3_optional =
UPB_DESC(FieldDescriptorProto_proto3_optional)(field_proto);
@ -642,6 +626,14 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
f->resolved_features = _upb_DefBuilder_DoResolveFeatures(
ctx, parent_features, unresolved_features, implicit);
f->label_ = (int)UPB_DESC(FieldDescriptorProto_label)(field_proto);
if (f->label_ == kUpb_Label_Optional &&
// TODO: remove once we can deprecate kUpb_Label_Required.
UPB_DESC(FeatureSet_field_presence)(f->resolved_features) ==
UPB_DESC(FeatureSet_LEGACY_REQUIRED)) {
f->label_ = kUpb_Label_Required;
}
if (!UPB_DESC(FieldDescriptorProto_has_name)(field_proto)) {
_upb_DefBuilder_Errf(ctx, "field has no name");
}
@ -661,6 +653,12 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
UPB_DESC(FieldDescriptorProto_has_type_name)(field_proto);
f->type_ = (int)UPB_DESC(FieldDescriptorProto_type)(field_proto);
if (f->type_ == kUpb_FieldType_Message &&
// TODO: remove once we can deprecate kUpb_FieldType_Group.
UPB_DESC(FeatureSet_message_encoding)(f->resolved_features) ==
UPB_DESC(FeatureSet_DELIMITED)) {
f->type_ = kUpb_FieldType_Group;
}
if (has_type) {
switch (f->type_) {

Loading…
Cancel
Save