-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove overlapping exclusive accesses in encoders #10819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove overlapping exclusive accesses in encoders #10819
Conversation
{JSON,Plist}{Encoder,Decoder} had overlapping accesses which were supposed to be mutually exclusive in their `with(pushedKey:)` methods. Removes those methods and the overlapping accesses.
@swift-ci Please test macOS |
@swift-ci Please smoke test Linux |
self.currentIndex += 1 | ||
return decoded | ||
guard let decoded = try self.decoder.unbox(self.container[self.currentIndex], as: Int.self) else { | ||
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: self.decoder.codingPath + [_JSONKey(index: self.currentIndex)], debugDescription: "Expected \(type) but found null instead.")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks DecodingError.valueNotFound
has duplicated _JSONKey(index: self.currentIndex)
in codingPath
.
Reproducing code:
import Foundation
struct A: Encodable {
var field1: String?
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(field1)
}
}
struct B: Decodable {
var field1: Int = 0
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
field1 = try container.decode(Int.self)
}
}
do {
let b = try JSONDecoder().decode(B.self, from: JSONEncoder().encode(A()))
print(b)
} catch {
print(error)
}
valueNotFound(Swift.Int, Swift.DecodingError.Context(codingPath: [Foundation.(_JSONKey in _12768CA107A31EF2DCE034FD75B541C9)(stringValue: "Index 0", intValue: Optional(0)), Foundation.(_JSONKey in _12768CA107A31EF2DCE034FD75B541C9)(stringValue: "Index 0", intValue: Optional(0))], debugDescription: "Expected Int but found null instead.", underlyingError: nil))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@norio-nomura Thanks for letting me know! I'll look into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@norio-nomura What compiler version/Xcode version are you using? I see a different error on my end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, nevermind — I was on the wrong Swift version myself. I get the same result as you do. I'll have to hunt down where we append the key to the coding path twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key is appended at the line that I commented on.
Same codes exist on each decode(_:)
methods of _JSONUnkeyedDecodingContainer
and _PlistUnkeyedDecodingContainer
.
If you wanted to keep this |
What's in this pull request?
{JSON,Plist}{Encoder,Decoder} had overlapping accesses which were supposed to be mutually exclusive in their
with(pushedKey:)
methods.Removes those methods and the overlapping accesses.