Skip to content

Commit

Permalink
make eta_reduction less aggressive (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan Maka <[email protected]>
  • Loading branch information
astro and Stephan Maka committed Jul 5, 2023
1 parent 3c7136a commit bcb3d10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bin/tests/data/eta_reduction.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ in

# other non-free forms
(map (f: {inherit f;}.double f.val) [ f ])

# don't reduce on more complex lambda bodies
(map (x: builtins.div 3 x) xs)
]
5 changes: 4 additions & 1 deletion lib/src/lints/eta_reduction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ impl Rule for EtaReduction {
if let Some(value_node) = body.value();
if let Some(value) = Ident::cast(value_node);

if arg.as_str() == value.as_str() ;
if arg.as_str() == value.as_str();

if let Some(lambda_node) = body.lambda();
if !mentions_ident(&arg, &lambda_node);
// lambda body should be no more than a single Ident to
// retain code readability
if let Some(_) = Ident::cast(lambda_node);

then {
let at = node.text_range();
Expand Down

0 comments on commit bcb3d10

Please sign in to comment.