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

Added support for root typealiases #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

666tos
Copy link

@666tos 666tos commented Aug 25, 2023

Mock template was customised to add single feature, which I named root-typealiases

Root typealiases are placed in root of the resulting file and are NOT nested inside type (as typealiases do).
They are meant to solve problem partially described in #184
Problem occurs when mock is generated for protocol name, which clashes with type from another library.
Since there is no concept of module in Sourcery/SwiftyMocky, compiler gets confused which type should be used for inheritance, for example:

Typealias example:

Our module:

    //sourcery: root-typealias = "Feature = MyModule.Feature"
    protocol Feature: AutoMockable {}

Another module:

    public struct Feature {}

Resulting Mock.generated.swift:

    open class FeatureMock: Feature, Mock { <--- 'Feature' is ambiguous for type lookup in this context
        public typealias Feature = MyModule.Feature
    } 

In this implementation this problem can be fixed by adding annotation for Feature protocol, like this:

    //sourcery: root-typealias = "Feature = MyModule.Feature"
    protocol Feature: AutoMockable {}

Resulting Mock.generated.swift:

    public typealias Feature = MyModule.Feature
    open class FeatureMock: Feature, Mock {}  <--- No ambiguity for type lookup in this context

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

Successfully merging this pull request may close these issues.

1 participant