-
-
Notifications
You must be signed in to change notification settings - Fork 624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated AutoMockable compilation issue due to variadic parameters #1265
Comments
Hello @art-divin @pocketal and I are working on a fix for this issue. |
Edit: since Swift itself does not support variadic arguments for closures, it is unreasonable to add such implementation detail. |
@rokridi I would like to mention that acceptable implementation would be: var totoArgsAnyStubWithSomeNameProtocolVoidCallsCount = 0
var totoArgsAnyStubWithSomeNameProtocolVoidCalled: Bool {
return totoArgsAnyStubWithSomeNameProtocolVoidCallsCount > 0
}
var totoArgsAnyStubWithSomeNameProtocolVoidReceivedArgs: ([(any StubWithSomeNameProtocol)])?
var totoArgsAnyStubWithSomeNameProtocolVoidReceivedInvocations: [[(any StubWithSomeNameProtocol)]] = []
var totoArgsAnyStubWithSomeNameProtocolVoidClosure: (([(any StubWithSomeNameProtocol)]) -> Void)?
func toto(args: any StubWithSomeNameProtocol...) {
totoArgsAnyStubWithSomeNameProtocolVoidCallsCount += 1
totoArgsAnyStubWithSomeNameProtocolVoidReceivedArgs = args
totoArgsAnyStubWithSomeNameProtocolVoidReceivedInvocations.append(args)
totoArgsAnyStubWithSomeNameProtocolVoidClosure?(args)
} i.e. keeping |
I am not 100% sure you actually need {% macro existentialClosureVariableTypeName typeName isVariadic -%}
{%- if typeName|contains:"any " and typeName|contains:"!" -%}
{{ typeName | replace:"any","(any" | replace:"!",")?" }}
{%- elif typeName|contains:"any " and typeName.isClosure and typeName|contains:"?" -%}
{{ typeName | replace:"any","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"any " and typeName|contains:"?" -%}
{{ typeName | replace:"any","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"some " and typeName|contains:"!" -%}
{{ typeName | replace:"some","(any" | replace:"!",")?" }}
{%- elif typeName|contains:"some " and typeName.isClosure and typeName|contains:"?" -%}
{{ typeName | replace:"some","(any" | replace:"?",")?" }}
{%- elif typeName|contains:"some " and typeName|contains:"?" -%}
{{ typeName | replace:"some","(any" | replace:"?",")?" }}
{%- elif isVariadic -%}
- {{ typeName }}...
+ [{{ typeName }}]
{%- else -%}
{{ typeName|replace:"some ","any " }}
{%- endif -%}
{%- endmacro %} |
@art-divin thanks for replying. I updated the issue's description. func foo(closure: (String...) -> Void) But this case is tricky to handle. |
@rokridi thank you, I see. So the branch I've referred above should support ClosureParameter.isVariadic. Please check |
Here is what the Stencil could look like (AutoMockable.txt), however we did not succeed at handling functions having a parameter which is a closure having a variadic parameter. Example: func foo(closure: (String...) -> Void) The corresponding mock: var func13ParamStringVoidVoidClosure: (((String) -> Void) -> Void)?
func func13(param: (String) -> Void) {
func13ParamStringVoidVoidCallsCount += 1
func13ParamStringVoidVoidClosure?(param)
} Expected mock: var func13ParamStringVoidVoidClosure: (((String...) -> Void) -> Void)?
func func13(param: (String...) -> Void) {
func13ParamStringVoidVoidCallsCount += 1
func13ParamStringVoidVoidClosure?(param)
} |
This is not compilable swift - checked yesterday also, to my amusement, variadic is only supported in function signature, does not work with variables. So, it'd work as:
|
I can pick it up from here, feel free to take a look at other, easy to reproduce bugs that are to be fixed for the next release: |
This PR should fix the issue |
Hello 👋
The current
AutoMockable.stencil
(version 2.1.7)
does not properly handle methods with variadic parameters, which causes a compilation failure.Example:
Given the following protocol:
The expected mock should like this:
However it looks like this:
Note that for each method
variadic
parameter the correspondingreceived argument
should be of type[ArgumentType]
and notArgumentType...
The text was updated successfully, but these errors were encountered: