Skip to content

Avoid rethrows method compilation error #274

@fummicc1

Description

@fummicc1

As of mockolo 2.1.1, rethrows method is not supported. The following mock produces compile error:

"error: call can throw, but the error is not handled; a function declared 'rethrows' may only throw if its parameter does"

/// @mockable
protocol ThrowableProtocol {
    func foo(action: () throws -> Int) rethrows
}

// ----- mock -----
class ThrowableProtocolMock: ThrowableProtocol {
    init() { }


    private(set) var fooCallCount = 0
    var fooHandler: ((() throws -> Int) throws -> ())?
    func foo(action: () throws -> Int) rethrows {
        fooCallCount += 1
        if let fooHandler = fooHandler {
            try fooHandler(action)
        }
        
    }
}

This is because rethrows only become throwable when parameter of the method has try keyword at the use site.

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