-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Description
Problem
When mockolo generates a mock for a protocol method that returns an array, it uses the syntax [TypeName]() for the default return value. This causes a build error in Swift 6 when the type is defined in another module and doesn't have a publicly accessible initializer.
Environment
- mockolo version: 2.4.0
- Xcode version: 26.0
- Swift version: 6.2
Steps to Reproduce
- Define a struct in Module A without a public parameterless initializer:
// Module A
public struct SomeModel: Sendable {
public let id: String
public init(entity: SomeEntity) {
self.id = entity.id
}
}- Define a protocol in Module B that returns an array of this type:
// Module B
/// @mockable
public protocol SomeRepository: Sendable {
func fetchItems(ids: [String]) -> [SomeModel]
}- Run mockolo to generate mocks (Mock module imports Module A and Module B)
- Build the Mock module
Generated Code
public func fetchItems(ids: [String]) -> [SomeModel] {
let handler = handlerState.withLock { state in
state.callCount += 1
return state.handler
}
if let handler = handler {
return handler(ids)
}
return [SomeModel]() // ❌ This line causes the error
}Build Error
error: cannot call value of non-function type '[SomeModel.Type]' (aka 'Array<SomeModel.Type>')
Expected Behavior
mockolo should generate [] instead of [TypeName]() for empty array default values:
return [] // ✅ Works correctly - type is inferred from return typeuhooi
Metadata
Metadata
Assignees
Labels
No labels