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

collapsible_let_in is incorrect #63

Open tazjin opened 1 year ago

tazjin commented 1 year ago

This reduction can only be applied if the inner let does not shadow any bindings, consider:

let
  x = 21;
  y = x;
in
let
  x = y * 2;
in x

# => evaluates to 42

statix wants to collapse this to

let
  x = 21;
  y = x;

  x = y * 2;
in x

Which no longer evaluates.

oppiliappan commented 1 year ago

very good find, thanks for the report!

tazjin commented 1 year ago

For context, I came across this earlier after somebody linked me statix and I looked into how to implement some of these lints as compiler warnings in Tvix (a modern rewrite of Nix, including a compatible language evaluator).

I don't know how invested you are in Nix and a project like this, but I think there's some potential for joining forces as our compiler has much deeper understanding of Nix code than just lexical analysis but we're not anywhere near the full potential for emitting warnings and other types of lints.

tazjin commented 1 year ago

btw, I have a few more issues like this which I found, I can report them all but they start sounding very nitpicky eventually :sweat_smile:

oppiliappan commented 1 year ago

i would love to pitch in where i can, i've been following tvix since i saw an announcement on lobste.rs a few months ago!

tazjin commented 1 year ago

Cool! If you're a chat kind of person, you can join us via IRC on irc.hackint.org in #tvl, we also have a public-inbox for email.

Could give you some pointers for how our current warnings/lints infrastructure works and such (I actually made some changes to that today inspired by statix).

oppiliappan commented 1 year ago

sounds perfect, ill check in on irc first thing tomorrow!