uber / mockolo

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

Wrap underlyingType if the type has existential any #235

Closed sidepelican closed 1 year ago

sidepelican commented 1 year ago

Add support for existential any.

Current behavior

protocol P {
    var foo: any P { get }
}

class PMock: P {
...
    private(set) var fooSetCallCount = 0
    private var _foo: any P!  { didSet { fooSetCallCount += 1 } }
    var foo: any P {
        get { return _foo }
        set { _foo = newValue }
    }
}

This is wrong. any P! must be (any P)!.

Expected

    private(set) var fooSetCallCount = 0
    private var _foo: (any P)!  { didSet { fooSetCallCount += 1 } }
    var foo: any P {
        get { return _foo }
        set { _foo = newValue }
    }

Misc

Keep current behavior for non any marked protocol for legacy codes.