Skip to content

Commit

Permalink
libnixf/Sema: ignore builtin liveness warning (#535)
Browse files Browse the repository at this point in the history
let ... in ... expr may create pass-through environments to
"emitLivenessWarning". However, this function does not consider the
"builtin" scope. In this case, `Def->syntax()` will be nullptr and thus
the server crashes.

Add the checking to "emitLivenessWarning" function.

Fixes: #533
  • Loading branch information
inclyc authored Jun 25, 2024
1 parent 9d01429 commit 6107557
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ void VariableLookupAnalysis::emitEnvLivenessWarning(
// the lambda signature.
if (Def->source() == Definition::DS_LambdaArg)
continue;
// Ignore builtins usage.
if (!Def->syntax())
continue;
if (Def->uses().empty()) {
Diagnostic &D = Diags.emplace_back(Diagnostic::DK_DefinitionNotUsed,
Def->syntax()->range());
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 @@ -316,4 +316,17 @@ rec {
ASSERT_EQ(Diags[0].range().lCur().line(), 3);
}

TEST_F(VLATest, Issue533) {
const char *Src = R"(
let ;
in 1
)";

std::shared_ptr<Node> AST = parse(Src, Diags);
VariableLookupAnalysis VLA(Diags);
VLA.runOnAST(*AST);

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

} // namespace

0 comments on commit 6107557

Please sign in to comment.