Skip to content

Commit

Permalink
[ObjC] Mark the syntax on FileDescriptor as deprecated.
Browse files Browse the repository at this point in the history
This really shouldn't be used for making decisions, so mark it as such.

PiperOrigin-RevId: 488683993
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed Nov 15, 2022
1 parent 7bb699b commit c79832b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions objectivec/GPBDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,16 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
@property(nonatomic, readonly, copy) NSString *package;
/** The objc prefix declared in the proto file. */
@property(nonatomic, readonly, copy, nullable) NSString *objcPrefix;
/** The syntax of the proto file. */
@property(nonatomic, readonly) GPBFileSyntax syntax;
/**
* The syntax of the proto file.
*
* This should not be used for making decisions about support
* features/behaviors, what proto2 vs. proto3 syntax has meant has evolved over
* time, and not more specific methods on the descriptors should be used
* instead.
*/
@property(nonatomic, readonly) GPBFileSyntax syntax
__attribute__((deprecated("Syntax is not a good way to decide things about behaviors.")));

@end

Expand Down
6 changes: 6 additions & 0 deletions objectivec/GPBDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,11 @@ - (instancetype)initWithFieldDescription:(void *)description
// - not repeated/map
// - not in a oneof (negative has index)
// - not a message (the flag doesn't make sense for messages)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
BOOL clearOnZero = ((file.syntax == GPBFileSyntaxProto3) && !isMapOrArray &&
(coreDesc->hasIndex >= 0) && !isMessage);
#pragma clang diagnostic pop
if (clearOnZero) {
coreDesc->flags |= GPBFieldClearHasIvarOnZero;
}
Expand All @@ -521,7 +524,10 @@ - (instancetype)initWithFieldDescription:(void *)description
// to be what the runtime was doing (even though it was wrong). This is
// only wrong in the rare cases an enum is declared in a proto3 syntax
// file but used for a field in the proto2 syntax file.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
BOOL isClosedEnum = (dataType == GPBDataTypeEnum && file.syntax != GPBFileSyntaxProto3);
#pragma clang diagnostic pop
if (isClosedEnum) {
coreDesc->flags |= GPBFieldClosedEnum;
}
Expand Down

0 comments on commit c79832b

Please sign in to comment.