Replies: 7 comments 3 replies
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@tgrapperon Wild stuff. So seems certainly an Apple/Swift bug. |
Beta Was this translation helpful? Give feedback.
-
I filed an issue in the Swift repo and feedback on this. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I was told to file a feedback to make Xcode/linker automatically add |
Beta Was this translation helpful? Give feedback.
-
I created this discussion before @tgrapperon pointed me to this ticket. This explains quite a bit :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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
Beta Was this translation helpful? Give feedback.
All reactions