Closed as not planned
Description
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.
protocol Key {
associated Value
static var defaultValue: Value
static func reduce(value: inout Value, nextValue: () -> Value)
}
struct AddIntKey: Key {
static var defaultValue: Int { 0 }
static func reduce(value: inout Int, nextValue: () -> Int) {
value += nextValue()
}
}
struct MultipleIntKey: Key {
static var defaultValue: Int { 0 }
static func reduce(value: inout Int, nextValue: () -> Int) {
value *= nextValue()
}
}
Expected behavior
@Test(arguments: [ // ✅
(AddIntKey.self, [1, 2], 3)
(MultipleIntKey.self, [1, 2], 2)
])
func reduce<Key: PreferenceKey>(
type: Key.Type, values: [Key.Value], expectedValues: Key.Value
) {
...
}
Actual behavior
@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