-
Notifications
You must be signed in to change notification settings - Fork 1.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Depency liveValue cannot be accessed in static library #1640
Comments
Hi @thd-bs, thank you very much for the easily reproducible sample project. I'm seeing the same. I also tried this with the version of One thing that does fix it is to move the This does feel like a Swift/Xcode bug, but it needs more exploration. Maybe a discussion needs to be opened on the Swift forums or an issue on the Swift repo. |
From a quick test, it seems that the compiler thinks that it doesn't need the file and simply doesn't compile it. Adding something in the same file as extension DoSomethingClient: DependencyKey {
public static var token: Void = ()
public static let liveValue: Self = .init(
doSomething: { print("Do something") }
)
} And in your app: let _ = DoSomethingClient.token When building a dynamic framework, it doesn't makes assumptions about clients and the file is compiled unconditionally. I don't know if there is a specific attribute to add that could help in this situation. |
@tgrapperon Wild stuff. So seems certainly an Apple/Swift bug. |
I filed an issue in the Swift repo and feedback on this. |
This seems to be expected behavior of static libraries. See here. That comment also provides a few potential work arounds. Since this isn't a bug with the library I'm going to convert it to a discussion. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description
When using a static library that defines a new
DependencyValues
property and defines itsTestDependencyKey
andDependencyKey
conformance in two separate extensions, force-accessing theliveValue
from a test usingDependencyValues.withValue(\.context, .live)
does not work and falls back on thetestValue
.This only happens with a static library. Doing this with a dynamic framework works as expected.
It also seems to happen just by running the app and using the dependency (which would make sense).
It seems in
_liveValue(_ key: Any.Type)
function of theOpenExistential
file, that the cast toDependencyKey
fails.Probably linked to how static libraries are compiled, not sure you can do anything about it on your side. Maybe if
DependencyKey
did not extendTestDependencyKey
? But that's maybe not an option.I have attached a sample vanilla project that reproduces this issue.
Checklist
main
branch of this package.Expected behavior
Accessing the
liveValue
from a static library splitting itsDependencyKey
/TestDependencyKey
conformance in 2 extension works.Actual behavior
Accessing the
liveValue
from a static library splitting itsDependencyKey
/TestDependencyKey
conformance in 2 extension fallbacks to thetestValue
.Steps to reproduce
DependencyIssue.zip
testValue
is accessed instead of theliveValue
, as expected by the forced live context.testValue
should also be used.If you do the same by repackaging the
DoSomethingStatic
library as a dynamic framework, it works as expected.The Composable Architecture version information
0.45.0
Destination operating system
iOS 16.1
Xcode version information
Xcode 14.1
Swift Compiler version information
The text was updated successfully, but these errors were encountered: