Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Computed Properties that return Self #185

Open
uhooi opened this issue Apr 12, 2022 · 2 comments
Open

Allow Computed Properties that return Self #185

uhooi opened this issue Apr 12, 2022 · 2 comments

Comments

@uhooi
Copy link
Collaborator

uhooi commented Apr 12, 2022

Computed properties that return Self also return Self in the mock.

/// @mockable
protocol FooRepository {
    static var shared: Self { get }
}

I would like the mock class return.

final class FooRepositoryMock: FooRepository {
    init() { }


    static private(set) var sharedSetCallCount = 0
-   static private var _shared: Self!  { didSet { sharedSetCallCount += 1 } }
-   static var shared: Self {
+   static private var _shared: FooRepositoryMock!  { didSet { sharedSetCallCount += 1 } }
+   static var shared: FooRepositoryMock {
        get { return _shared }
        set { _shared = newValue }
    }
}

Reference

Version

  • Mockolo: 1.7.0
@sidepelican
Copy link
Collaborator

If it were Self, would there be any problems?

@uhooi
Copy link
Collaborator Author

uhooi commented Sep 14, 2023

@sidepelican Mock causes a compile error.

❌  .../OutputMocks.swift:99:99: stored property cannot have covariant 'Self' type

    static private var _shared: Self!  { didSet { sharedSetCallCount += 1 } }
                       ^
❌  .../OutputMocks.swift:99:99: mutable property cannot have covariant 'Self' type

    public static var shared: Self {
                                   ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants