tersesystems/blindsight

Arguments.apply breaks type safety?

anovstrup opened this issue · 2 comments

The documentation states that

Arguments in Blindsight are type checked, in constrast [sic] to the SLF4J API, which takes an Any.

The implementation of Arguments.apply appears to contradict this, however. Since it takes variadic arguments of type Any, one can call Arguments(any, value, whatsoever); the implementation does not enforce that each value is an Argument, a BObject, or has a ToArgument instance in the implicit scope. There are safer ways to construct Arguments (e.g., Arguments.fromInstance(only) + valid + types + allowed), but the convenience of Arguments(...) and the fact that it's used in the documented examples makes it a fairly tempting trap for unwary developers.

A checked implementation that retains the convenience of Arguments.apply could perhaps be written as a macro -- I'm not sure it's possible otherwise. In the meantime, could the current implementation be renamed Arguments.unchecked (or something similar), its use discouraged, and the examples in the documentation rewritten to use a checked mechanism to construct Arguments?

Yes, I've done this myself.

Arguments needs a refactoring -- I think the correct (but painful) way to do this is to have a Product22 style type argument, i.e. args3[T1, T2, T3] and so on, and do the same thing with the Arguments.apply method so it's no longer taking a raw array.

This is fixed now in 2.0.0.