Skip to content

Commit dd2b330

Browse files
authored
Deprecate FieldDescriptor label (#1766)
Add a second storage that can be used to avoid deprecation warnings from the code within the file that does have to touch/inspect the value. Finishes up tracking changes in protocolbuffers/protobuf#20687.
1 parent 9d469c6 commit dd2b330

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Sources/SwiftProtobufPluginLibrary/Descriptor.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -1091,8 +1091,11 @@ public final class FieldDescriptor {
10911091

10921092
/// This should never be called directly. Use isRequired and isRepeated
10931093
/// helper methods instead.
1094-
// TODO(thomasvl): @available(*, deprecated, message: "Use isRequired or isRepeated instead.")
1095-
public let label: Google_Protobuf_FieldDescriptorProto.Label
1094+
@available(*, deprecated, message: "Use isRequired or isRepeated instead.")
1095+
public var label: Google_Protobuf_FieldDescriptorProto.Label { _label }
1096+
1097+
// Storage for `label`, used by other apis.
1098+
private var _label: Google_Protobuf_FieldDescriptorProto.Label
10961099

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

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

0 commit comments

Comments
 (0)