Skip to content

Commit 213d2d0

Browse files
committed
Deprecate FieldDescriptor.isOptional.
This is the start of tracking the upstream changes to move away from Label and the "optional" bit in there. See protocolbuffers/protobuf#20687 for the start of it. Update the comments on isRequired and isRepeated also.
1 parent b3df4c3 commit 213d2d0

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Sources/SwiftProtobufPluginLibrary/Descriptor.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,18 +1092,19 @@ public final class FieldDescriptor {
10921092
/// optional/required/repeated
10931093
public let label: Google_Protobuf_FieldDescriptorProto.Label
10941094

1095-
/// Shorthand for `label` == `.required`.
1096-
///
1097-
/// NOTE: This could also be a map as the are also repeated fields.
1095+
/// Whether or not the field is required. For proto2 required fields and
1096+
/// Editions `LEGACY_REQUIRED` fields.
10981097
public var isRequired: Bool {
10991098
// Implementation comes from FieldDescriptor::is_required()
11001099
features.fieldPresence == .legacyRequired
11011100
}
1102-
/// Shorthand for `label` == `.optional`
1103-
public var isOptional: Bool { label == .optional }
1104-
/// Shorthand for `label` == `.repeated`
1101+
/// Whether or not the field is repeated/map field.
11051102
public var isRepeated: Bool { label == .repeated }
11061103

1104+
/// Use !isRequired() && !isRepeated() instead.
1105+
@available(*, deprecated, message: "Use !isRequired() && !isRepeated() instead.")
1106+
public var isOptional: Bool { label == .optional }
1107+
11071108
/// Is this field packable.
11081109
public var isPackable: Bool {
11091110
// This logic comes from the C++ FieldDescriptor::is_packable() impl.

Sources/protoc-gen-swift/MessageGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ class MessageGenerator {
117117
"\(e.containingType.fullName) has the option message_set_wire_format but \(e.fullName) is a non message extension field."
118118
return
119119
}
120-
guard e.isOptional else {
120+
guard !e.isRequired && !e.isRepeated else {
121121
errorString =
122-
"\(e.containingType.fullName) has the option message_set_wire_format but \(e.fullName) is not a \"optional\" extension field."
122+
"\(e.containingType.fullName) has the option message_set_wire_format but \(e.fullName) cannot be required nor repeated extension field."
123123
return
124124
}
125125
}

0 commit comments

Comments
 (0)