Skip to content

Added support for root typealiases#350

Open
666tos wants to merge 1 commit into
MakeAWishFoundation:masterfrom
666tos:feature/root_typealias
Open

Added support for root typealiases#350
666tos wants to merge 1 commit into
MakeAWishFoundation:masterfrom
666tos:feature/root_typealias

Conversation

@666tos
Copy link
Copy Markdown

@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