// Code from https://github.com/cx-org/CombineX/blob/CXNamespace/Sources/CXNamespace/CXNamespace.swift
public protocol CXWrapper {
associatedtype Base
var base: Base { get }
init(_ base: Base)
}
public protocol CXWrappable {
associatedtype CX: CXWrapper where CX.Base == Self
var cx: CX { get }
}
public extension CXWrappable {
var cx: CX {
return CX(self)
}
}
// Note CX == Self is inferred here. Adding this requirement produce a warning.
public protocol CXSelfWrapping: CXWrappable, CXWrapper where Base == Self /* CX == Self */ {}
public extension CXSelfWrapping {
var base: Base {
return self
}
init(_ base: Base) {
self = base
}
}
AFAICS CXSelfWrapping don't have any associated type, and all requirements have default implementation. Any type can conforms to CXSelfWrapping for free. However no type can conform to it.
// Type 'A' does not conform to protocol 'CXSelfWrapping'
// Do you want to add protocol stubs?
class A: CXSelfWrapping {}
// Type 'Optional<Wrapped>' does not conform to protocol 'CXSelfWrapping'
// Do you want to add protocol stubs?
extension Optional: CXSelfWrapping {}
// Type 'Optional<Wrapped>' does not conform to protocol 'CXWrappable'
// Type 'Optional<Wrapped>' does not conform to protocol 'CXWrapper'
extension Optional: CXSelfWrapping {
public typealias CX = Optional<Wrapped>
}
Is this a bug or intended behavior, Am I doing wrong?