Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Crash occurs when diffing two LocalizedStringKeys with special interpolations #97

Open
daltonclaybrook opened this issue Sep 3, 2023 · 0 comments

Comments

@daltonclaybrook
Copy link

Describe the bug
Passing a LocalizedStringKey constructed with basic string interpolation works correctly. For example, the following code works as you would expect:

let name = "Dalton"
let control: LocalizedStringKey = "Static string"
let success: LocalizedStringKey = "Hello, \(name)!"

// This prints:
// - "Static string"
// + "Hello, Dalton!"
print(diff(control, success) ?? "No diff")

However, passing a LocalizedStringKey that uses any of the other variations of string interpolation supported by LocalizedStringKey results in a crash:

let control: LocalizedStringKey = "Static string"
let crash1: LocalizedStringKey = "Date: \(Date(), style: .date)"
let crash2: LocalizedStringKey = "Date range: \(Date.distantPast...Date.distantFuture)"
let crash3: LocalizedStringKey = "Time: \(Duration.seconds(10), format: .time(pattern: .minuteSecond))"

print(diff(control, crash1) ?? "No diff") // crash!
print(diff(control, crash2) ?? "No diff") // crash!
print(diff(control, crash3) ?? "No diff") // crash!

The crash (SIGABRT) occurs on this line:

Array(Mirror(reflecting: children[0].value).children)[0].value as! (Any, Formatter?)

The console output:

Could not cast value of type 'SwiftUI.LocalizedStringKey.FormatArgument.Token' (0x1fea477e8) to 'NSFormatter' (0x1fd708ed8).
2023-09-02 19:11:54.584602-0500 dump-bug[32884:11397570] Could not cast value of type 'SwiftUI.LocalizedStringKey.FormatArgument.Token' (0x1fea477e8) to 'NSFormatter' (0x1fd708ed8).

Expected behavior
I expect that the above code would not result in a crash and would instead print an appropriate diff between the provided strings.

Environment

  • swift-custom-dump version: 1.0.0
  • Xcode Version 14.3.1 (14E300c)
  • Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
  • OS: macOS 13.4.1 (c) (22F770820d) and iOS 16.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant