Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-254

Make BSONValue conform to Equatable

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Won't Fix
    • None
    • None
    • None

    Description

      Currently BSONValue does not conform to Equatable, but this is actually a little weird. BSONValue's are really just a bunch of totally Equatable types, so it would only make sense that BSONValue should also be Equatable.

      For the most part, this is simple, but for the particular case of Array, a simple Equatable conformant implementation is not correct. This is because we extend Array as a BSONValue, and require nothing of the Array's constituent elements. What this means is that every Array becomes a BSONValue. This means that making BSONValue conform to Equatable as-is would cause all Array's to be compared using BSONValue's equality implementation. This is quite obviously incorrect, because an Array of non-BSONValue's should not be compared as if it was a BSONValue.

      The way around this is to use conditional conformance, which is specified in SWIFT-215. Making Array conform to BSONValue only when its constituent elements are BSONValue would avoid the mentioned problem and only use the Equatable implementation for BSONValue when it makes sense. For the most part, we are looking for something like this sketch:

      extension Array: BSONValue where Element: BSONValue {
          ...
      }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              may.hoque@mongodb.com May Hoque
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: