You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swift-ci opened this issue
Feb 1, 2018
· 5 comments
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
error: type 'Foo' does not conform to protocol 'Decodable'
public enum Foo: Bar, Codable {
^
error: type 'Foo' does not conform to protocol 'Encodable'
public enum Foo: Bar, Codable {
Change the RawValue of `Foo` to String, and the problem goes away.
Looks like the issue are the following extensions that this is trying to match against:
extensionRawRepresentablewhereRawValue == ${type}, Self : Encodable {
/// Encodes this value into the given encoder.////// This function throws an error if any values are invalid for the given/// encoder's format.////// - Parameter encoder: The encoder to write data to.@_inlineable// FIXME(sil-serialize-all)publicfuncencode(toencoder: Encoder) throws {
varcontainer = encoder.singleValueContainer()
trycontainer.encode(self.rawValue)
}
}
extensionRawRepresentablewhereRawValue == ${type}, Self : Decodable {
/// Creates a new instance by decoding from the given decoder.////// This initializer throws an error if reading from the decoder fails, or/// if the data read is corrupted or otherwise invalid.////// - Parameter decoder: The decoder to read data from.@_inlineable// FIXME(sil-serialize-all)publicinit(fromdecoder: Decoder) throws {
letdecoded = trydecoder.singleValueContainer().decode(RawValue.self)
guardletvalue = Self(rawValue: decoded) else {
throwDecodingError.dataCorrupted(
DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Cannot initialize \(Self.self) from invalid \(RawValue.self) value \(decoded)"))
}
self = value
}
}
Now that we have conditional conformance, I think we can reasonably change this code to use that.
@belkadan correctly pointed out in Radar that we can't conform protocols to other protocols with conditional conformance, so we might need to find a way to improve the diagnostics here instead. Not sure if it'll be possible without special-casing this, but this bears investigation nonetheless.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Environment
MacOS Sierra 10.12.6 (16G29)
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
Additional Detail from JIRA
md5: 7c5d0c095962aac1ffbda000990ce04a
Issue Description:
The following code does not compile
Generating 2 errors:
Change the RawValue of `Foo` to String, and the problem goes away.
Expected Result:
Codable is derived entirely.
Discovered along side with: https://bugs.swift.org/browse/SR-6897
The text was updated successfully, but these errors were encountered: