I personally think that it is also a strength that anytype doesn’t require type constraints.
For example in your case you are over-constraining the add function.
You want a type that has the + operator, but you constraining it to runtime integers and runtime floats. But @Vector types as well as comptime_int and comptime_float also support +.
I think in this case it actually hurts readability to have this complex validation function.
Furthermore I think the error message provided by the compiler is usually better and more actionable (it tells me directly which property or function is missing) than the user defined error message which often ends up being rather vague (what is a numeric type? Why is comptime_int not considered a numeric type?):
error: invalid operands to binary expression: 'bool' and 'bool'
return value + value;
~~~~~~^~~~~~~
referenced by:
main: test.zig:20:32
-----------------------------------------------------------
error: The type provided bool isnt numeric
else => @compileError("The type provided " ++ @typeName(@TypeOf(value)) ++ " isn't numeric"),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
main: test.zig:20:32
I also think that anytype is a bit of a tooling issue. Even with your proposal it’s still hard to communicate to the user what properties a type must fulfill. I think either way we would need the language server to analyze the function and tells us which properties the input must fulfill or which functions it should have.