I have 3 modules:
Module 1:
struct Apple {}
Module 2:
protocol Fruit{}
extension Apple: Fruit {}
Module 3:
let any: Any = Apple()
let fruit = any as! Fruit // <- force conversion failed, any doesn't conform to Fruit
struct Basket where Content: Fruit {}
let appleBasket: Basket<Apple> = .init() // another crash by EXEC_BAD_ACCESS, but it passes compiling 
if I move
extension Apple: Fruit {}
to the module 3, the crashes are all gone.
Could someone explain to me how extension works in Swift?
Ray_Fix
(Ray Fix)
2
This thread may help: Retroactive Conformances vs. Swift-in-the-OS Doing retroactive conformance from other modules is problematic, as you discovered.
1 Like
Jon_Shier
(Jon Shier)
3
Please include your various visibility modifiers. But in general I don’t think the casting will work if the conformance isn’t publicly available and imported.