From e0213bb616f3349c62c275bdbeb574f405531a79 Mon Sep 17 00:00:00 2001 From: Dimitris Koutsogiorgas Date: Wed, 18 Oct 2023 13:00:07 -0700 Subject: [PATCH] [swift] Better handling for edge case field names --- .../src/main/swift/SwiftEdgeCases.swift | 18 +++++++++--------- .../proto/kotlin/swift_edge_cases.proto | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift b/wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift index 09ff642748..aaab703e28 100644 --- a/wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift +++ b/wire-tests-swift/no-manifest/src/main/swift/SwiftEdgeCases.swift @@ -8,7 +8,7 @@ public struct SwiftEdgeCases { @ProtoDefaulted public var `return`: String? @ProtoDefaulted - public var string: String? + public var type: String? public var unknownFields: Foundation.Data = .init() public init(configure: (inout Self) -> Swift.Void = { _ in }) { @@ -22,9 +22,9 @@ extension SwiftEdgeCases { @_disfavoredOverload @available(*, deprecated) - public init(`return`: Swift.String? = nil, string: Swift.String? = nil) { + public init(`return`: Swift.String? = nil, type: Swift.String? = nil) { self._return.wrappedValue = `return` - self._string.wrappedValue = string + self._type.wrappedValue = type } } @@ -64,25 +64,25 @@ extension SwiftEdgeCases : Proto2Codable { public init(from protoReader: Wire.ProtoReader) throws { var `return`: Swift.String? = nil - var string: Swift.String? = nil + var type: Swift.String? = nil let token = try protoReader.beginMessage() while let tag = try protoReader.nextTag(token: token) { switch tag { case 1: `return` = try protoReader.decode(Swift.String.self) - case 2: string = try protoReader.decode(Swift.String.self) + case 2: type = try protoReader.decode(Swift.String.self) default: try protoReader.readUnknownField(tag: tag) } } self.unknownFields = try protoReader.endMessage(token: token) self._return.wrappedValue = `return` - self._string.wrappedValue = string + self._type.wrappedValue = type } public func encode(to protoWriter: Wire.ProtoWriter) throws { try protoWriter.encode(tag: 1, value: self.`return`) - try protoWriter.encode(tag: 2, value: self.string) + try protoWriter.encode(tag: 2, value: self.type) try protoWriter.writeUnknownFields(unknownFields) } @@ -94,14 +94,14 @@ extension SwiftEdgeCases : Codable { public init(from decoder: Swift.Decoder) throws { let container = try decoder.container(keyedBy: Wire.StringLiteralCodingKeys.self) self._return.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "return") - self._string.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "string") + self._type.wrappedValue = try container.decodeIfPresent(Swift.String.self, forKey: "type") } public func encode(to encoder: Swift.Encoder) throws { var container = encoder.container(keyedBy: Wire.StringLiteralCodingKeys.self) try container.encodeIfPresent(self.`return`, forKey: "return") - try container.encodeIfPresent(self.string, forKey: "string") + try container.encodeIfPresent(self.type, forKey: "type") } } diff --git a/wire-tests/src/commonTest/proto/kotlin/swift_edge_cases.proto b/wire-tests/src/commonTest/proto/kotlin/swift_edge_cases.proto index 23a6b77d5b..96edf002dd 100644 --- a/wire-tests/src/commonTest/proto/kotlin/swift_edge_cases.proto +++ b/wire-tests/src/commonTest/proto/kotlin/swift_edge_cases.proto @@ -19,5 +19,5 @@ package squareup.protos.kotlin.swift_modules; message SwiftEdgeCases { optional string return = 1; - optional string string = 2; + optional string type = 2; }