AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
978 stars 75 forks source link

Fix for Swift 4.2 changes in Optional<->Any conversions #201

Closed stevenkramer closed 5 years ago

stevenkramer commented 5 years ago

In Xcode 10 beta 5, the unboxing of optional values started to fail, because the code simultaneously tried to test for an empty optional and a successful cast. Breaking this up in two steps fixes the issue.

ilyapuchka commented 5 years ago

have you tried swift42 branch?

stevenkramer commented 5 years ago

Yes, was using that since dadb688 on previous betas. This started to manifest itself around beta 4.

stevenkramer commented 5 years ago

Happened trying to auto-wire an optional initializer argument.

ilyapuchka commented 5 years ago

ah, I didn't notice that you opened this for this branch, my bad

zintus commented 5 years ago

FYI, i experience runtime crash with swift 4.2 and here is swift forums thread on roots of issue https://forums.swift.org/t/conditional-casting-with-any-as-type-parameter/16163

ilyapuchka commented 5 years ago

@stevenkramer can you add a test that is failing without this change?

stevenkramer commented 5 years ago

@ilyapuchka done

ilyapuchka commented 5 years ago

This is not related to Swift 4.2, it also happens with Swift 4. It's due to reusing previously resolved instances - if the order of resolves is different in your test it works, but it can't reuse instances resolved for optional type. It also only happens for structs, not classes.