mockingbird
mockingbird copied to clipboard
Always getting "Use of protocol 'CaseIterableDefaultsLast' as a type must be written 'any CaseIterableDefaultsLast'" Compiler Error
New Issue Checklist
- [x] I updated the framework and generator to the latest version
- [x] I searched the existing GitHub issues and list of common problems
Overview
I created a new protocol:
/// An enum where the last case value is "unknown" and can be used as a default catch-all.
public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable {}
public extension CaseIterableDefaultsLast where RawValue: Decodable, AllCases: BidirectionalCollection {
/// Initializes an enum such that if a known raw value is found, then it is decoded.
/// Otherwise the last case ("unknown") is used.
/// - Parameter decoder: A decoder.
init(from decoder: Decoder) throws {
if let value = try Self(rawValue: decoder.singleValueContainer().decode(RawValue.self)) {
self = value
} else if let lastValue = Self.allCases.last {
self = lastValue
} else {
throw DecodingError.valueNotFound(
Self.Type.self,
.init(codingPath: decoder.codingPath, debugDescription: "CaseIterableDefaultsLast")
)
}
}
}
But when run the test, the generated files got compiler error:
Use of protocol 'CaseIterableDefaultsLast' as a type must be written 'any CaseIterableDefaultsLast' Compiler Error
Example
If the generator produces code that is malformed or does not compile, please provide:
- A minimal example of the original source
- The actual mocking code generated
@available(*, unavailable, message: "'CaseIterableDefaultsLast' inherits from the externally-defined type 'Decodable & CaseIterable & RawRepresentable' which needs to be declared in a supporting source file")
public func mock(_ type: CaseIterableDefaultsLast.Protocol, file: StaticString = #file, line: UInt = #line) -> CaseIterableDefaultsLastMock {
fatalError()
}
I always getting this error that turns my unit test cannot be tested. Please give me suggestion how to solve this problem? Or maybe need some enhancement from the Mockingbirds?
Expected Behavior
@available(*, unavailable, message: "'CaseIterableDefaultsLast' inherits from the externally-defined type 'Decodable & CaseIterable & RawRepresentable' which needs to be declared in a supporting source file")
public func mock(_ type: any CaseIterableDefaultsLast, file: StaticString = #file, line: UInt = #line) -> CaseIterableDefaultsLastMock {
fatalError()
}
Environment
- Mockingbird CLI version (
mockingbird version
) - Xcode and Swift version (
swift --version
) - Package manager (CocoaPods, Carthage, SPM project, SPM package)
- Unit testing framework (XCTest, Quick/Nimble)
- Custom configuration
- [ ] Mockingbird ignore files
- [ ] Supporting source files