Skip to content

Commit

Permalink
libnixf/Sema: set attrrange to it's key for var lookup (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 9, 2024
1 parent d68caac commit 4ad2d87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ VariableLookupAnalysis::dfsAttrs(const SemaAttrs &SA,
DefBuilder DB;
// For each static names, create a name binding.
for (const auto &[Name, Attr] : SA.staticAttrs())
DB.add(Name, Attr.value());
DB.add(Name, &Attr.key());

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

Expand Down
19 changes: 18 additions & 1 deletion libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ TEST_F(VLATest, LookupLet) {
ASSERT_EQ(Diags.size(), 0);
}

TEST_F(VLATest, LookupLet2) {
std::shared_ptr<Node> AST = parse("let a = 1; b = a; in a", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

ASSERT_TRUE(AST);
ASSERT_EQ(AST->kind(), Node::NK_ExprLet);

const Expr *Body = static_cast<const ExprLet &>(*AST).expr();
ASSERT_TRUE(Body);
ASSERT_EQ(Body->kind(), Node::NK_ExprVar);
auto Result = VLA.query(*static_cast<const ExprVar *>(Body));
ASSERT_EQ(Result.Kind, VLAResultKind::Defined);
ASSERT_EQ(Result.Def->syntax()->lCur().column(), 4);
ASSERT_EQ(Result.Def->syntax()->rCur().column(), 5);
}

TEST_F(VLATest, LookupWith) {
std::shared_ptr<Node> AST = parse("with 1; foo", Diags);
VariableLookupAnalysis VLA(Diags);
Expand Down Expand Up @@ -133,7 +150,7 @@ TEST_F(VLATest, LivenessNested) {
ASSERT_EQ(Diags.size(), 1);

ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_DefinitionNotUsed);
ASSERT_EQ(Diags[0].range().lCur().column(), 8);
ASSERT_EQ(Diags[0].range().lCur().column(), 4);
ASSERT_EQ(Diags[0].tags().size(), 1);
ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded);
}
Expand Down

0 comments on commit 4ad2d87

Please sign in to comment.