Skip to content

Commit

Permalink
Tolerate more shapes of SourceKit output
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Oct 15, 2024
1 parent 2610c2d commit aad81ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## Main

#### Breaking

* None.

#### Enhancements

* Build without warnings with Swift 6 compiler.
[SimplyDanny](https://github.com/SimplyDanny)

* Generate docs cleanly with Swift 6 compiler.
[John Fairhurst](https://github.com/johnfairh)
[#821]((https://github.com/realm/SourceKitten/issues/821)

#### Bug Fixes

* None.

## 0.36.0

##### Breaking
Expand Down
22 changes: 11 additions & 11 deletions Source/SourceKittenFramework/JSONOutput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,28 @@ public func toJSON(_ object: Any, options: JSONSerialization.WritingOptions? = n
- returns: JSON-serializable value.
*/
public func toNSDictionary(_ dictionary: [String: SourceKitRepresentable]) -> NSDictionary {
var anyDictionary = [String: Any]()
for (key, object) in dictionary {
switch object {
func toNSDictionaryValue(_ value: SourceKitRepresentable) -> Any {
switch value {
case let object as [SourceKitRepresentable]:
anyDictionary[key] = object.map { toNSDictionary($0 as! [String: SourceKitRepresentable]) }
return object.map { toNSDictionaryValue($0) }
case let object as [[String: SourceKitRepresentable]]:
anyDictionary[key] = object.map { toNSDictionary($0) }
return object.map { toNSDictionary($0) }
case let object as [String: SourceKitRepresentable]:
anyDictionary[key] = toNSDictionary(object)
return toNSDictionary(object)
case let object as String:
anyDictionary[key] = object
return object
case let object as Int64:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Bool:
anyDictionary[key] = NSNumber(value: object)
return NSNumber(value: object)
case let object as Any:
anyDictionary[key] = object
return object
default:
fatalError("Should never happen because we've checked all SourceKitRepresentable types")
}
}
return anyDictionary.bridge()

return dictionary.mapValues(toNSDictionaryValue).bridge()
}

#if !os(Linux)
Expand Down

0 comments on commit aad81ea

Please sign in to comment.