@@ -221,7 +221,7 @@ class MessageGenerator {
221221 p. print ( " \n " )
222222 generateTraverse ( printer: & p)
223223 p. print ( " \n " )
224- generateMessageImplementationBase ( printer: & p)
224+ generateMessageEquality ( printer: & p)
225225 p. outdent ( )
226226 p. print ( " } \n " )
227227
@@ -345,22 +345,23 @@ class MessageGenerator {
345345 p. print ( " } \n " )
346346 }
347347
348- private func generateMessageImplementationBase ( printer p: inout CodePrinter ) {
349- p. print ( " \( visibility) func _protobuf_generated_isEqualTo(other : \( swiftFullName) ) -> Bool { \n " )
348+ private func generateMessageEquality ( printer p: inout CodePrinter ) {
349+ p. print ( " \( visibility) static func ==(lhs: \( swiftFullName ) , rhs : \( swiftFullName) ) -> Bool { \n " )
350350 p. indent ( )
351351 var compareFields = true
352352 if let storage = storage {
353- p. print ( " if _storage !== other ._storage { \n " )
353+ p. print ( " if lhs. _storage !== rhs ._storage { \n " )
354354 p. indent ( )
355355 p. print ( " let storagesAreEqual: Bool = " )
356356 if storage. storageProvidesEqualTo {
357- p. print ( " _storage.isEqualTo(other: other ._storage) \n " )
357+ p. print ( " lhs. _storage.isEqualTo(other: rhs ._storage)\n " )
358358 compareFields = false
359359 }
360360 }
361361 if compareFields {
362362 generateWithLifetimeExtension ( printer: & p,
363- alsoCapturing: " other " ) { p in
363+ alsoCapturing: " rhs " ,
364+ selfQualifier: " lhs " ) { p in
364365 for f in fields {
365366 f. generateFieldComparison ( printer: & p)
366367 }
@@ -374,9 +375,9 @@ class MessageGenerator {
374375 p. outdent ( )
375376 p. print ( " } \n " )
376377 }
377- p. print ( " if unknownFields != other .unknownFields {return false} \n " )
378+ p. print ( " if lhs. unknownFields != rhs .unknownFields {return false} \n " )
378379 if isExtensible {
379- p. print ( " if _protobuf_extensionFieldValues != other ._protobuf_extensionFieldValues {return false} \n " )
380+ p. print ( " if lhs. _protobuf_extensionFieldValues != rhs ._protobuf_extensionFieldValues {return false} \n " )
380381 }
381382 p. print ( " return true \n " )
382383 p. outdent ( )
@@ -457,25 +458,33 @@ class MessageGenerator {
457458 throws canThrow: Bool = false ,
458459 returns: Bool = false ,
459460 alsoCapturing capturedVariable: String ? = nil ,
461+ selfQualifier qualifier: String ? = nil ,
460462 body: ( inout CodePrinter ) -> Void
461463 ) {
462464 if storage != nil {
463465 let prefixKeywords = " \( returns ? " return " : " " ) " +
464466 " \( canThrow ? " try " : " " ) "
465467 p. print ( prefixKeywords)
466468
469+ let selfQualifier : String
470+ if let qualifier = qualifier {
471+ selfQualifier = " \( qualifier) . "
472+ } else {
473+ selfQualifier = " "
474+ }
475+
467476 if let capturedVariable = capturedVariable {
468477 // withExtendedLifetime can only pass a single argument,
469478 // so we have to build and deconstruct a tuple in this case:
470- let actualArgs = " (_storage, \( capturedVariable) ._storage) "
479+ let actualArgs = " ( \( selfQualifier ) _storage, \( capturedVariable) ._storage) "
471480 let formalArgs = " (_args: (_StorageClass, _StorageClass)) "
472481 p. print ( " withExtendedLifetime( \( actualArgs) ) { \( formalArgs) in \n " )
473482 p. indent ( )
474483 p. print ( " let _storage = _args.0 \n " )
475484 p. print ( " let \( capturedVariable) _storage = _args.1 \n " )
476485 } else {
477486 // Single argument can be passed directly:
478- p. print ( " withExtendedLifetime(_storage) { (_storage: _StorageClass) in \n " )
487+ p. print ( " withExtendedLifetime( \( selfQualifier ) _storage) { (_storage: _StorageClass) in \n " )
479488 p. indent ( )
480489 }
481490 }
0 commit comments