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

Avoid duplicated variable under if-macro syntax #279

Merged
merged 5 commits into from
Dec 3, 2024

Conversation

fummicc1
Copy link
Collaborator

@fummicc1 fummicc1 commented Dec 1, 2024

This PR addresses #273 and performs uniqueEntities method for IfMacroModel before rendering because entities inside IfMacroModel are not treated as NominalModel's entities.

I think IfMacro support is insufficient yet (see #263 ) but I am focusing to fix #273 in this PR.

  • Input
/// @mockable
protocol PresentableListener: AnyObject {
    #if RELEASE
    func run(value: Int)
    func run(value: String)
    #endif
}
  • Output
BeforeAfter
class PresentableListenerMock: PresentableListener {
    init() { }

    #if RELEASE

    private(set) var runCallCount = 0
    var runHandler: ((Int) -> ())?
    func run(value: Int) {
        runCallCount += 1
        if let runHandler = runHandler {
            runHandler(value)
        }
        
    }

    // not supporting overload
    private(set) var runCallCount = 0
    var runHandler: ((String) -> ())?
    func run(value: String) {
        runCallCount += 1
        if let runHandler = runHandler {
            runHandler(value)
        }
        
    }
    #endif
}
class PresentableListenerMock: PresentableListener {
    init() { }

    #if RELEASE

    private(set) var runCallCount = 0
    var runArgValues = [Int]()
    var runHandler: ((Int) -> ())?
    func run(value: Int) {
        runCallCount += 1
        runArgValues.append(value)
        if let runHandler = runHandler {
            runHandler(value)
        }
        
    }

    private(set) var runValueCallCount = 0
    var runValueArgValues = [String]()
    var runValueHandler: ((String) -> ())?
    func run(value: String) {
        runValueCallCount += 1
        runValueArgValues.append(value)
        if let runValueHandler = runValueHandler {
            runValueHandler(value)
        }
        
    }
    #endif
}

@fummicc1 fummicc1 changed the title Use uniqueModel for IfMacroModel subModels before rendering Avoid duplicated variable under if-macro syntax Dec 1, 2024
@fummicc1 fummicc1 marked this pull request as ready for review December 1, 2024 10:21
@fummicc1 fummicc1 requested review from sidepelican and uhooi December 1, 2024 10:21
Copy link
Collaborator

@sidepelican sidepelican left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is good, but it's not perfect.
The same issue will continue to occur with protocols like the following:

/// @mockable
protocol PresentableListener {
    #if DEBUG
    func run(value: Int)
    #endif
    func run(value: Double)
}

But because it makes things better than they are now, I think it is best to merge this change for now.

@sidepelican sidepelican merged commit 954b952 into uber:master Dec 3, 2024
3 checks passed
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.

overload inside if macro produces same variables
2 participants