Variadic generics function error #7622
-
I'm writing some code to be converted to wgsl. I tried writing a function called
If I remove
Is it out of scope for variadic generics to be able to be passed into function overloads, or a bug? Code: import playground;
typealias vec2 = float2;
typealias vec3 = float3;
typealias vec4 = float4;
vec3 col3<each T>(expand each T args) where T == float {
return toLin(vec3(expand each args));
}
vec3 toLin(vec3 color) {
return pow(color, vec3(2.2));
}
float4 imageMain(uint2 dispatchThreadID, int2 screenSize)
{
vec3 color = col3(1.0, 1.0, 1.0);
return vec4(color, 1.0);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Looks like slang doesn't handle varargs well in this type of situation. You should create an issue. In general, I think function overrides are better for this situation since using varargs implies the function should be able to take 4+ arguments, when it can't. |
Beta Was this translation helpful? Give feedback.
-
This is one the key differences between generics and templates. In a generic type system, the compiler must be able to prove type match before specializing the generics. In this specific case, there is no way for the compiler to know how many elements your Therefore this error is correct compiler behavior, not a bug. |
Beta Was this translation helpful? Give feedback.
This is one the key differences between generics and templates.
In a generic type system, the compiler must be able to prove type match before specializing the generics. In this specific case, there is no way for the compiler to know how many elements your
args
will expand to, and therefore will not be able to match that call to anyfloat3()
constructors.Therefore this error is correct compiler behavior, not a bug.