Skip to content

Commit

Permalink
libnixf: disable escaping with warning for builtin (#528)
Browse files Browse the repository at this point in the history
Giving an "escaping with" warning to builtin variables like `true`,
`false` or `null` is not very suitable:


![image](https://github.com/nix-community/nixd/assets/29816865/daeb04ad-37a6-4f36-bf0f-81397e9a5725)
  • Loading branch information
Origami404 authored Jun 23, 2024
1 parent 528c544 commit 74f013a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void VariableLookupAnalysis::lookupVar(const ExprVar &Var,
Def->usedBy(Var);
Results.insert({&Var, LookupResult{LookupResultKind::Defined, Def}});

if (EnclosedWith) {
if (EnclosedWith && !Def->isBuiltin()) {
// Escaping from "with" to outer scope.
// https://github.com/NixOS/nix/issues/490

Expand Down
8 changes: 8 additions & 0 deletions libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ TEST_F(VLATest, EscapingWith) {
ASSERT_EQ(D.notes()[1].range().rCur().offset(), 7);
}

TEST_F(VLATest, EscapingWithButBuiltin) {
std::shared_ptr<Node> AST = parse("with { a = 1; }; [ a true false null ]", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

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

TEST_F(VLATest, InheritRec) {
// Make sure inheirt (expr), the expression is binded to "NewEnv".
std::shared_ptr<Node> AST =
Expand Down

0 comments on commit 74f013a

Please sign in to comment.