Skip to content

Specify module for method parameter types to avoid ambiguity #305

@wvteijlingen-npo

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) { ... }
}

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