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
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
Additional Detail from JIRA
Votes
1
Component/s
Compiler
Labels
Bug, Codable, Miscompile
Assignee
None
Priority
Medium
md5: 8911146b2c988206beb0ee7c8b7a1a1f
Issue Description:
I've run into a pretty weird issue, where the compiler seems to generate wrong code for an OptionSet conforming to Codable. It looks like the compiler generates code that expects a [String : Any]. However, OptionSets are encoded as numbers.
This leads to an error:
Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [CodableTestCore.MyStruct.(CodingKeys in _AC1835A39B063DF80DB968377AD3AADB).options], debugDescription: "Expected to decode Dictionary<String, Any> but found a number instead.", underlyingError: nil)): file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-900.0.69.2/src/swift/stdlib/public/core/ErrorType.swift, line 181
I isolated the issue and created a sample package. You need to build the package with swift build -c release.
One thing I discovered is that the file names matter. Renaming A.swift to something that comes after MyOptionSet.swift in the alphabet does not trigger this issue.
The text was updated successfully, but these errors were encountered:
I am unable to reproduce the crash with Swift version 4.2 (swiftlang-1000.0.16.9 clang-1000.10.25.3) bundled with Xcode 10 beta 2. Using Swift 4.1 I still get the crash.
@belkadan, do you have any idea if this has been fixed in Swift 4.2?
For anyone else having this issue using Xcode 9 and swift 4.1, you can fix it by reordering your swift files under compile sources and putting your codable OptionSets at the top. Swift 4.2 resolved this for me, however since Xcode 10 is still in beta that won't be an option for a few more months.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.CodableArea → standard library: `Codable` and co.compilerThe Swift compiler in itself
Attachment: Download
Environment
macOS 10.12.6
Apple Swift version 4.0.2 (swiftlang-900.0.69.2 clang-900.0.38)
Additional Detail from JIRA
md5: 8911146b2c988206beb0ee7c8b7a1a1f
Issue Description:
I've run into a pretty weird issue, where the compiler seems to generate wrong code for an OptionSet conforming to Codable. It looks like the compiler generates code that expects a [String : Any]. However, OptionSets are encoded as numbers.
This leads to an error:
I isolated the issue and created a sample package. You need to build the package with swift build -c release.
One thing I discovered is that the file names matter. Renaming A.swift to something that comes after MyOptionSet.swift in the alphabet does not trigger this issue.
The text was updated successfully, but these errors were encountered: