Skip to content

Empty dictionaries of certain types throw an error when decoding #32

@mkeiser

Description

@mkeiser

Expected Behavior

Some empty dictionaries that have been encoded with CBOREncoder throw a type mismatch error when the data is decoded again with CBORDecoder.
To me this seems like a relatively severe bug.

Actual Behavior

See provided test methods.

Steps To Reproduce

Test methods I added to CBORDecoderTests. The first one currently fails, the second one succeeds.

    /// Fails!
    func testEmptyDictionaryRoundTripUInt64Key() throws {
        let dict = [UInt64: String]()
        let data = try CBOREncoder().encode(dict)
        let dict2: [UInt64: String] = try CBORDecoder().decode(from: data)
        XCTAssertEqual(dict, dict2)
    }

    /// Succeeds
    func testEmptyDictionaryRoundTripIntKey() throws {
        let dict = [Int: String]()
        let data = try CBOREncoder().encode(dict)
        let dict2: [Int: String] = try CBORDecoder().decode(from: data)
        XCTAssertEqual(dict, dict2)
    }

Other types fail too, for example dictionaries with Int32 keys.

Project Version

6fbd643

The OS/Variant where this issue occurs.

  • iOS
  • macOS
  • tvOS
  • watchOS
  • Mac Catalyst
  • Other (Please specify in "Additional Context" section)

The version of Xcode that was used when this issue appeared.

15.0.1 (15A507)

What was the environment in which the issue appeared?

  • CBORCoding.xcodeproj
  • Package.swift
  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Other (Please specify in "Additional Context" section)

Additional Context

No response

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions