nix-community / rnix-parser

A Nix parser written in Rust [maintainer=@oberblastmeister]
MIT License
364 stars 44 forks source link

LetIn with inherit entry gives wrong node for body #125

Closed darichey closed 2 years ago

darichey commented 2 years ago

If a let expression uses inherit, the typed api incorrectly gives the corresponding NODE_INHERIT as the body of the let.

use rnix::ast::HasEntry;

fn main() {
    let nix_expr = "let inherit (x) y; in y";
    if let rnix::ast::Expr::LetIn(let_in) =
        rnix::Root::parse(&nix_expr).ok().unwrap().expr().unwrap()
    {
        println!("{:?}", let_in.entries().collect::<Vec<_>>());
        println!("{:?}", let_in.body());
    }
}
[Inherit(Inherit(NODE_INHERIT@4..18))]
Some(Inherit(Inherit(NODE_INHERIT@4..18)))

The cause is the same as the cause of #121: NODE_INHERIT is both a valid Expr and Entry.

In this case, I wonder why is it an Expr?