Skip to content

Commit

Permalink
libnixf: inherit expression should comes from "NewEnv" for recursive … (
Browse files Browse the repository at this point in the history
#467)

…attrs
  • Loading branch information
inclyc authored Apr 26, 2024
1 parent 6748240 commit f78e80c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,10 @@ std::shared_ptr<EnvNode> VariableLookupAnalysis::dfsAttrs(

auto NewEnv = std::make_shared<EnvNode>(Env, DB.finish(), Syntax);

// inherit (expr) attrs;
// ~~~~~~<------- this expression should have "parent scope".
for (const auto &[_, Attr] : SA.staticAttrs()) {
if (!Attr.value())
continue;
dfs(*Attr.value(), Attr.fromInherit() ? Env : NewEnv);
dfs(*Attr.value(), NewEnv);
}

dfsDynamicAttrs(SA.dynamicAttrs(), NewEnv);
Expand Down
10 changes: 10 additions & 0 deletions libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,14 @@ TEST_F(VLATest, EscapingWith) {
ASSERT_EQ(D.notes().size(), 2);
}

TEST_F(VLATest, InheritRec) {
// Make sure inheirt (expr), the expression is binded to "NewEnv".
std::shared_ptr<Node> AST =
parse("rec { inherit (foo) bar; foo.bar = 1; }", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

ASSERT_EQ(Diags.size(), 0);
}

} // namespace

0 comments on commit f78e80c

Please sign in to comment.