redundant_pattern_bind is incorrect
tazjin opened this issue · 0 comments
tazjin commented
Empty pattern bindings assert types, consider:
let
crudeAssertAttrs = x @ { ... }: x;
in crudeAssertAttrs 42
=> fails to evaluate (`42` is not a set)
statix
wants to reduce this to:
let
crudeAssertAttrs = x: x;
in crudeAssertAttrs 42
which now evaluates to 42
. This could allow an unexpected value to accidentally pass further than expected and introduce subtle bugs.
I initially thought this might be possible to correctly implement in some cases, for example if the body of a function does something with the argument that ensures it is an attrset (e.g. an attrset-related operator).
However, doing that correctly requires branch analysis and probably full runtime information, so now I think this check is impossible to do lexically, for example:
let
something = ...;
f = x @ { ... }: if something then x else x.key;
in
...