swift-macro-examples icon indicating copy to clipboard operation
swift-macro-examples copied to clipboard

Macro type check for protocol failed

Open miku1958 opened this issue 2 years ago • 0 comments

Hi, I tried to add a macro to convert ObjC's Class (AnyClass in Swift) to the actual type. https://github.com/miku1958/swift-macro-examples/commit/e9027e4014d95d7830f3dd9af024d6e764e679b6

I've added two functions here that are implemented in ObjC, and I've added them as swift versions in the example classConforming is to retrieve the class that conform the ObjcProtocol from a dictionary, it return AnyClass objectConforming is to retrieve the object that conform the ObjcProtocol from a dictionary, it return Any

I can't write a Swift version directly due to compiler limitations, so I'd like to borrow the Macro implementation

The problem happened when I used classConforming and convert the ObjcProtocol to: classConforming(to: ObjcProtocol.self) as? ObjcProtocol.Type

Compiler give me this error: Cannot convert value of type '(any ObjcProtocol.Type)?' to type '(any ObjcProtocol).Type?' in coercion

I tried to return another Generic Type or return Any directly but fail, any way I can fix it?

Thanks!

miku1958 avatar Feb 16 '23 08:02 miku1958