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

Unable to resolve inherited type 'AnyObject' #324

Open
2 tasks done
lhunath opened this issue Mar 13, 2023 · 3 comments
Open
2 tasks done

Unable to resolve inherited type 'AnyObject' #324

lhunath opened this issue Mar 13, 2023 · 3 comments
Labels
generator bug Causes malformed generated code

Comments

@lhunath
Copy link

lhunath commented Mar 13, 2023

New Issue Checklist

Overview

When a protocol extends AnyObject, the generator does generate a mock for the protocol but the generated mock does not adopt the protocol it is generating for. As a result, we have a mock whose type does not conform the protocol and is unusable in practice.

Example

Failure scenario, UserProject: AnyObject yields a UserProjectMock which does not : UserProject:

public protocol UserProject: AnyObject {
    var isFavorite: Bool { get set }
}

// MARK: - Mocked UserProject
public final class UserProjectMock: Mockingbird.Mock {
  typealias MockingbirdSupertype = Projects.UserProject
  public static let mockingbirdContext = Mockingbird.Context()
  public let mockingbirdContext = Mockingbird.Context(["generator_version": "0.20.0", "module_name": "Projects"])
}

Success scenario, bare UserProject yields a UserProjectMock which does : UserProject:

public protocol UserProject {
    var isFavorite: Bool { get set }
}

public final class UserProjectMock: Projects.UserProject, Mockingbird.Mock {
  typealias MockingbirdSupertype = Projects.UserProject
  public static let mockingbirdContext = Mockingbird.Context()
  public let mockingbirdContext = Mockingbird.Context(["generator_version": "0.20.0", "module_name": "Projects"])

  // MARK: Mocked isFavorite
  public var `isFavorite`: Bool {
    ...
  }
}

Expected Behavior

The conformance of a protocol to : AnyObject should not affect the mock generation since the mock is already a class type.

Environment

  • Mockingbird CLI version: 0.20.0
  • Xcode and Swift version: swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
  • Package manager: SPM
  • Unit testing framework: XCTest
@lhunath lhunath added the generator bug Causes malformed generated code label Mar 13, 2023
@lhunath
Copy link
Author

lhunath commented Mar 13, 2023

Running with --verbose, we see:

Unable to resolve inherited type 'AnyObject' for 'UserProject'

@lhunath lhunath changed the title Mocks fail to adopt a protocol that conforms : AnyObject Unable to resolve inherited type 'AnyObject' Mar 13, 2023
@lhunath
Copy link
Author

lhunath commented Mar 13, 2023

Work-around, add this to MockingbirdSupport/Swift/AnyObject.swift:

protocol AnyObject {}

@Narayane
Copy link

Narayane commented May 3, 2023

#321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator bug Causes malformed generated code
Projects
None yet
Development

No branches or pull requests

2 participants