Fix infinite recursion when casting `AnySerializable` to wrong type (#147)
This commit is contained in:
parent
bd14dae265
commit
03d5386e58
|
@ -194,7 +194,7 @@ extension Defaults.Serializable {
|
||||||
return anyObject
|
return anyObject
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let nextType = T.Serializable.self as? any Defaults.Serializable.Type else {
|
guard let nextType = T.Serializable.self as? any Defaults.Serializable.Type, nextType != T.self else {
|
||||||
// This is a special case for the types which do not conform to `Defaults.Serializable` (for example, `Any`).
|
// This is a special case for the types which do not conform to `Defaults.Serializable` (for example, `Any`).
|
||||||
return T.bridge.deserialize(anyObject as? T.Serializable) as? T
|
return T.bridge.deserialize(anyObject as? T.Serializable) as? T
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,4 +466,10 @@ final class DefaultsAnySerializableTests: XCTestCase {
|
||||||
|
|
||||||
waitForExpectations(timeout: 10)
|
waitForExpectations(timeout: 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testWrongCast() {
|
||||||
|
let value = Defaults.AnySerializable(false)
|
||||||
|
XCTAssertEqual(value.get(Bool.self), false)
|
||||||
|
XCTAssertNil(value.get(String.self))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue