-
Notifications
You must be signed in to change notification settings - Fork 1
Support WebAssembly + fix Linux collection-cast crash #30
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,7 +15,13 @@ extension Dictionary: Cacheable { | |||||||||||||||||||||||||||||||
| - Returns: The casted value for the given key, or `nil` if the key doesn't exist or the cast fails. | ||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||
| public func get<Item>(_ key: Key, as: Item.Type = Item.self) -> Item? { | ||||||||||||||||||||||||||||||||
| guard let value = self[key] as? Item else { | ||||||||||||||||||||||||||||||||
| // Route through an explicit `Any` boxing step before the conditional cast. This avoids | ||||||||||||||||||||||||||||||||
| // `swift_dynamicCastFailure` / `_arrayForceCast` aborts on Linux and WASI when casting an | ||||||||||||||||||||||||||||||||
| // `Optional<Any>` that wraps a collection type (e.g. `[SomeStruct]`): without the | ||||||||||||||||||||||||||||||||
| // intermediate cast, the runtime takes the `Optional<Any>` → `[T]` forced-array-cast path, | ||||||||||||||||||||||||||||||||
| // which is not implemented the same way off Darwin. Boxing to `Any` first normalises the | ||||||||||||||||||||||||||||||||
| // dynamic type to the concrete `Item` path. | ||||||||||||||||||||||||||||||||
| guard let value = (self[key] as Any) as? Item else { | ||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of boxing the optional value into
Suggested change
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure that
@PublishedandObservableObjectcompile correctly across all platforms and build configurations (especially when this file is compiled incrementally or in isolation), we should explicitly importCombinewhen it is available.