Skip to content

Deprecate FieldDescriptor label #1766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Sources/SwiftProtobufPluginLibrary/Descriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,11 @@ public final class FieldDescriptor {

/// This should never be called directly. Use isRequired and isRepeated
/// helper methods instead.
// TODO(thomasvl): @available(*, deprecated, message: "Use isRequired or isRepeated instead.")
public let label: Google_Protobuf_FieldDescriptorProto.Label
@available(*, deprecated, message: "Use isRequired or isRepeated instead.")
public var label: Google_Protobuf_FieldDescriptorProto.Label { _label }

// Storage for `label`, used by other apis.
private var _label: Google_Protobuf_FieldDescriptorProto.Label

/// Whether or not the field is required. For proto2 required fields and
/// Editions `LEGACY_REQUIRED` fields.
Expand All @@ -1101,7 +1104,7 @@ public final class FieldDescriptor {
features.fieldPresence == .legacyRequired
}
/// Whether or not the field is repeated/map field.
public var isRepeated: Bool { label == .repeated }
public var isRepeated: Bool { _label == .repeated }

/// Use !isRequired() && !isRepeated() instead.
@available(*, deprecated, message: "Use !isRequired && !isRepeated instead.")
Expand Down Expand Up @@ -1129,7 +1132,7 @@ public final class FieldDescriptor {
var _hasOptionalKeyword: Bool {
// This logic comes from the C++ FieldDescriptor::has_optional_keyword()
// impl.
proto3Optional || (file.edition == .proto2 && label == .optional && oneofIndex == nil)
proto3Optional || (file.edition == .proto2 && _label == .optional && oneofIndex == nil)
}
@available(*, deprecated, message: "Please open a GitHub issue if you think functionality is missing.")
public var hasOptionalKeyword: Bool {
Expand Down Expand Up @@ -1346,9 +1349,9 @@ public final class FieldDescriptor {
// helper instead of access `label` directly, they won't need this, but for
// consistency, remap `label` to expose the pre Editions/Features value.
if self.features.fieldPresence == .legacyRequired && proto.label == .optional {
self.label = .required
self._label = .required
} else {
self.label = proto.label
self._label = proto.label
}
self.options = proto.options
self.oneofIndex = proto.hasOneofIndex ? proto.oneofIndex : nil
Expand Down