Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes infinite recursion when casting AnySerializable to wrong type #147

Merged
merged 3 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Defaults/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ extension Defaults.Serializable {
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`).
return T.bridge.deserialize(anyObject as? T.Serializable) as? T
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,10 @@

waitForExpectations(timeout: 10)
}

Check warning on line 469 in Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func testWrongCast() {
let value = Defaults.AnySerializable(false)
XCTAssertEqual(value.get(Bool.self), false)

Check warning on line 472 in Tests/DefaultsTests/DefaultsAnySeriliazableTests.swift

View workflow job for this annotation

GitHub Actions / lint

XCTest Specific Matcher Violation: Prefer the specific matcher 'XCTAssertFalse' instead (xct_specific_matcher)
XCTAssertNil(value.get(String.self))
}
}
Loading