oppiliappan / statix

lints and suggestions for the nix programming language
https://git.peppe.rs/languages/statix/about
MIT License
552 stars 21 forks source link

"These let-in expressions are collapsible" is incorrect #85

Open elaforge opened 3 months ago

elaforge commented 3 months ago

The idiomatic way to shadow a variable in nix is vie nested lets:

let x = 10; in let x_ = x; in let x = x_ + 1; in x

But statix collapses the lets seemingly without paying attention to the variables defined:

let x = 10;  x_ = x;  x = x_ + 1; in x

This is error, x is defined twice. Or it could turn it into infinite recursion by changing (x: let x_ = x; in let x = x_ + 1; in x) 10 to (x: let x_ = x; x = x_ + 1; in x) 10

Since lets define a mutually recursive block, they can only be merged if the inner let doesn't define any variables defined in the outer one.

This is true of 0.5.8 as in nixpkgs, looks like it's up to date with the repo, which is also at 0.5.8.