Skip to content

Commit

Permalink
libnixf/Sema: fix misplaced nested liveness diagnostic (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 8, 2024
2 parents 05819cd + 7c28007 commit 351c7fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ void VariableLookupAnalysis::lookupVar(const ExprVar &Var,
EnvNode *CurEnv = Env.get();
std::shared_ptr<Definition> Def;
for (; CurEnv; CurEnv = CurEnv->parent()) {
if (CurEnv->defs().contains(Name))
if (CurEnv->defs().contains(Name)) {
Def = CurEnv->defs().at(Name);
break;
}
// Find the most nested `with` expression, and set uses.
if (CurEnv->isWith() && !EnclosedWith) {
EnclosedWith = true;
Expand Down
13 changes: 13 additions & 0 deletions libnixf/test/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,17 @@ TEST_F(VLATest, LivenessArg) {
ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded);
}

TEST_F(VLATest, LivenessNested) {
std::shared_ptr<Node> AST = parse("let y = 1; in x: y: x + y", Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

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].tags().size(), 1);
ASSERT_EQ(Diags[0].tags()[0], DiagnosticTag::Faded);
}

} // namespace

0 comments on commit 351c7fe

Please sign in to comment.