Skip to content

[Bug] Generics syntax is incorrectly generated from protocols that have associated types with multiple conformances #107

Closed
@ngimelliUW

Description

@ngimelliUW

Swift Version

6.0

Package Version

0.1.0

Bug Description

It may be desirable to generate a mock from a protocol with associated types. Sometimes, those associated types may themselves have multiple conformances. For example:

public protocol InMemoryStoreProtocol: Sendable {

    associatedtype Key: Hashable & Sendable
    associatedtype Value: Sendable

    ...
}

in this case, we require that both the key and the value be sendable. The key has the additional requirement of being hashable. However, if you add the @Mocked macro to this protocol, it will generate the following:

public final class InMemoryStoreProtocolMock<Key:, Value: Sendable>: InMemoryCacheProtocol { ... }

You can see that the Key generic argument is succeeded by a colon, but does not actually list any required conformances (like Value does with Sendable)! This only happens when the associated type has multiple conformance requirements.

Steps to Reproduce

  1. Create a protocol that has an associated type.
  2. Add multiple conformance requirements on that associated type using & syntax.
  3. Expand the macro; you will see the bug.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions