From f78e80cd485b2d68ed359799e2fda99b46605495 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 26 Apr 2024 16:08:56 +0800 Subject: [PATCH] =?UTF-8?q?libnixf:=20inherit=20expression=20should=20come?= =?UTF-8?q?s=20from=20"NewEnv"=20for=20recursive=20=E2=80=A6=20(#467)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …attrs --- libnixf/src/Sema/VariableLookup.cpp | 4 +--- libnixf/test/Sema/VariableLookup.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libnixf/src/Sema/VariableLookup.cpp b/libnixf/src/Sema/VariableLookup.cpp index 70040124a..d5056398d 100644 --- a/libnixf/src/Sema/VariableLookup.cpp +++ b/libnixf/src/Sema/VariableLookup.cpp @@ -177,12 +177,10 @@ std::shared_ptr VariableLookupAnalysis::dfsAttrs( auto NewEnv = std::make_shared(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); diff --git a/libnixf/test/Sema/VariableLookup.cpp b/libnixf/test/Sema/VariableLookup.cpp index a3771d765..7b98ef591 100644 --- a/libnixf/test/Sema/VariableLookup.cpp +++ b/libnixf/test/Sema/VariableLookup.cpp @@ -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 AST = + parse("rec { inherit (foo) bar; foo.bar = 1; }", Diags); + VariableLookupAnalysis VLA(Diags); + VLA.runOnAST(*AST); + + ASSERT_EQ(Diags.size(), 0); +} + } // namespace