Trouble with transitive dependency traits

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?

5 Likes

Hi! Thanks for posting a reproducible example :slight_smile: This seems like a bug.

Do you know which version of Swift you’re using here? If you could file a Github issue for swift package manager, it would be much appreciated!

1 Like

Thank you for confirming I really appreciate it. I have cut some corners on that issue, but if that is getting in the way please just let me know.

1 Like

Thank you so much! Taking a look at this now.

Out of curiosity, if you remove the line:

.default(enabledTraits: [])

From your Package A, does this yield the same result?