It is a known bug: SR‐631. It is labelled resolved, but I don’t think it is included in the latest release.
Rearranging the compile sources list (as you figured out on your own) is the recommended workaround.
For Xcode projects (re)generated by the package manager, the source list ends up alphabetical by file name, so the compilation order can be controlled indirectly that way (i.e. by naming them Foo.swift
and FooBar.swift
, instead of Foo.swift
and Bar.swift
).