uber / mockolo

Efficient Mock Generator for Swift
Apache License 2.0
805 stars 85 forks source link

Consider method that has `some` parameter. #212

Closed fummicc1 closed 1 year ago

fummicc1 commented 1 year ago

Problem

When we try to create a protocol that has method like below,

public protocol Foo {}

public struct Bar: Foo {}

// NG
/// @mockable
public protocol Controller {
    func method(foo: some Foo) -> Int
}

Output mock fails to compile like this.

Screenshot 2023-02-04 at 22 11 17

Reason & Workaround

The reason is some keyword can't be used at the parameter of closure if the closure is placed at return type.

public var methodHandler: ((some Foo) -> (Int))? // compile error happens

We can avoid this case by using <F: Foo> generics parameter instead of some keyword.

public protocol Foo {}

public struct Bar: Foo {}

// OK
/// @mockable
public protocol Controller {
    func method<F: Foo>(foo: F) -> Int
}

but I think it is valuable to investigate if it can be fixed or not.

Sample to reproduce