Skip to content

Specify module for method parameter types to avoid ambiguity #305

Description

@wvteijlingen-npo

Our codebase has multiple modules that contain types with the same name, for example: ModuleA.Foo and ModuleB.Foo. The generated mock file will import both ModuleA and ModuleB, leading to ambiguity for the Foo type.

Would it be possible to always specify the module, thereby resolving any ambiguity?

Example

Input

// ModuleA

public struct Foo {}

public protocol ProtocolInModuleA {
  func doSomething(with: Foo) -> Void
}
// ModuleB

public struct Foo {}

Current mocks

// Mocks.generated.swift

import ModuleA
import ModuleB

class ProtocolInModuleAMock {
    // These references to Foo are ambiguous
    var doSomethingArgValues = [Foo]()
    var doSomethingHandler: ((Foo) -> ())?
    func doSomething(with: Foo) { ... }
}

Expected mocks

// Mocks.generated.swift

import ModuleA
import ModuleB

class ProtocolInModuleAMock {
    // These references to Foo are explicitly disambiguated by including the module
    var doSomethingArgValues = [ModuleA.Foo]()
    var doSomethingHandler: ((ModuleA.Foo) -> ())?
    func doSomething(with: ModuleA.Foo) { ... }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions