Brightify / Cuckoo

Boilerplate-free mocking framework for Swift!
MIT License
1.67k stars 175 forks source link

Plenty errors in GeneratedMocks.ts for swift 5.8.1 #474

Closed normanzb closed 7 months ago

normanzb commented 1 year ago

Hi there,

Does Cuckoo support swift 5.8.1? if not then is there a plan to support 5.8+? when i generated the mocks with cuckoo 1.10.3 I got plenty errors such as:

Invalid conversion from throwing function of type '(NameOfAProtocol) throws -> ()' to non-throwing function type '(NameOfAProtocol) -> Void'
Use of protocol 'NameOfAProtocol' as a type must be written 'any NameOfAProtocol'

Replace 'NameOfAProtocol' with '(any NameOfAProtocol)'

thx!

MatyasKriz commented 1 year ago

Hey, @normanzb, I haven't tested Cuckoo with Swift 5.8.1, but it seems like this issue might be a pretty big deal. I wonder why the any is necessary all of a sudden? According to this article it should be an error from Swift 6 onward.

MatyasKriz commented 7 months ago

Welp, seems like it's not that big of a deal based on the lack of reactions. If you're still encountering this issue and have a proposal on how to fix it, please reopen the issue and let me know. 🙂

oliver98844 commented 5 months ago

FYI, I encountered the same problem recently.

I found that Swift requires the any keyword because a protocol uses Self in its definition.

The Self enables the compiler to know it is an Opaque type for better optimization. However, the generated mock needs to store it as a property or pass it in a method parameter. So, it requires the any as an Existential type.

In my case, the protocol conforms to Equatable originally. But I remove the Equatable from the protocol definition. So, the generated mock is now okay without the any as a type.

MatyasKriz commented 5 months ago

I've added any to all protocols in 2.0.3, so it shouldn't cause warnings at all going forward.

oliver98844 commented 5 months ago

@MatyasKriz Nice, thanks for the efforts. 👍