Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import Foundation

extension _TOMLDecoder: SingleValueDecodingContainer {
var context: TOMLKey {
codingPath.last as! TOMLKey
guard let key = codingPath.last else {
return TOMLKey.super
}
if let key = key as? TOMLKey {
return key
}
if let intValue = key.intValue {
return TOMLKey(intValue: intValue)
}
return TOMLKey(stringValue: key.stringValue)
}

@inline(__always)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ import Foundation

extension _TOMLDecoder: SingleValueDecodingContainer {
var context: TOMLKey {
codingPath.last as! TOMLKey
guard let key = codingPath.last else {
return TOMLKey.super
}
if let key = key as? TOMLKey {
return key
}
if let intValue = key.intValue {
return TOMLKey(intValue: intValue)
}
return TOMLKey(stringValue: key.stringValue)
}

% for native_type in native_types:
Expand Down
10 changes: 10 additions & 0 deletions Tests/TOMLDecoderTests/TOMLDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ struct TOMLDecoderTests {
}
}

@Test func optionalScalarArrayMismatchThrowsWithoutTrapping() throws {
struct Probe: Decodable {
let b: Bool?
}

#expect(throws: (any Error).self) {
try TOMLDecoder().decode(Probe.self, from: "b = [1, 2, 3]\n")
}
}

@Test
func foundationDateDecoding() throws {
struct Player: Codable, Equatable {
Expand Down
Loading