You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have some generic interface in the codebase. And I'd request generic function support for @Test macro.
The following is a simplified version of my use case.
protocolKey{
associated Value
staticvar defaultValue:Valuestaticfunc reduce(value:inoutValue, nextValue:()->Value)}structAddIntKey:Key{staticvardefaultValue:Int{0}staticfunc reduce(value:inoutInt, nextValue:()->Int){
value +=nextValue()}}structMultipleIntKey:Key{staticvardefaultValue:Int{0}staticfunc reduce(value:inoutInt, nextValue:()->Int){
value *=nextValue()}}
@Test(arguments:[ // ❌: The @Test attribute cannot be applied to a generic function.(AddIntKey.self,[1,2],3)(MultipleIntKey.self,[1,2],2)])func reduce<Key:PreferenceKey>(
type:Key.Type, values:[Key.Value], expectedValues:Key.Value){...}
Steps to reproduce
No response
swift-testing version/commit hash
No response
Swift & OS version (output of swift --version && uname -a)
No response
The text was updated successfully, but these errors were encountered:
Would have the type [Any] rather than something like [some PreferenceKey] as you presumably intended. The types of a test's parameters must be explicitly specified in the test function's declaration because during macro expansion, we can only rely on the syntax (the specific characters the developer typed and saved into the source file) and do not have semantic type information for the test function's arguments.
Even if we assume for a moment that the syntax above were valid anyway, swift-testing discovers tests at runtime. A generic function may have an unbounded number of specializations at runtime, and the Swift runtime would require swift-testing to know how to specialize the test function before it could be called.
If you really wanted to do something like this, consider an abstraction over a common implementation function instead of using parameterization:
Description
We have some generic interface in the codebase. And I'd request generic function support for
@Test
macro.The following is a simplified version of my use case.
Expected behavior
Actual behavior
Steps to reproduce
No response
swift-testing version/commit hash
No response
Swift & OS version (output of
swift --version && uname -a
)No response
The text was updated successfully, but these errors were encountered: