Unsolvable namespace issue *apparently a Swift package bug

Simplified example:

protocol VertexBuffer: Identifiable {
    var id: UInt32 { get }

enum GL {
    struct VertexBuffer: VertexBuffer { // error because it's a struct inheriting itself?


Can I fix this name conflict without giving it a terrible name like VertexBufferProtocol, or naming my buffer obj-c style, GLVertexBuffer?

For whatever reason I can't put a protocol in an enum. Maybe there's a good reason for it, but in that case it would be cool to have actual namespaces instead of abusing enums :slight_smile:

I'm pretty sure the only thing I can do is move this to a completely separate module :pensive:

You can qualify the protocol reference with the module name:

protocol VertexBuffer: Identifiable { ... }

enum GL {
  struct VertexBuffer: WhateverYourModuleNameIs.VertexBuffer {
    // ...

That only works if it's in a separate module, they are in the same file.

No, it also works in the same file: Compiler Explorer

Note the -module-name argument passed to the compiler; this is what SwiftPM would pass during compilation based on the name of your target.

It does not work if I use the module name. but it works when I write it in lower case letters :eyes:

Ok. I see where the problem is, Swift package manager is just very confused. My module has a capitalised name, but Swift is treating the final executable name as the module "namespace", so these don't match.

Very confusing behavior.

Like this:

products: [.executable(name: "my-module", targets: ["MyModule"])],
targets: [
    .executableTarget(name: "MyModule", dependencies: ["GLAD", "SDL2"]),

Swift package manager is using the wrong name here.

This is arguably a bug, executables by convention are lower case, but Swift types and modules are not. No matter which one you change, something is going to look wrong.