I’ve just recently begun adopting traits in a package of mine, and I ran into a surprising problem. Here’s the situation, as best as I can narrow down. I apologize, I know how hard it is to follow abstract, meaningless names…
Package A:
traits: [
"Foo",
"Bar",
.default(enabledTraits: []),
],
Package B:
dependencies: [
.package(url: "A", branch: "main", traits: ["Foo", "Bar"]),
],
Package C:
dependencies: [
.package(url: "B", branch: "main"),
],
The important bits are C depends only on B directly. And B cannot build without enabling some traits on A.
Yet, with this arrangement, Package C cannot be build because B fails. This appears to be because its stated requirements for A-Foo and A-Bar is not applied. I find this surprising, since B has explicitly and unconditionally enabled both. It certainly seems like when building C, A is being built with the default traits.
I can workaround this by explicitly adding this line to C's dependencies:
.package(url: "A", branch: "main", traits: ["Foo", "Bar"]),
However, this is really strange, because C does not have a direct dependency on A, only on B.
Is this expected?