Skip to content

Commit

Permalink
libnixf: omit pedantic liveness warning on lambda arg (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 26, 2024
1 parent 6d56957 commit 6748240
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 22 deletions.
5 changes: 5 additions & 0 deletions libnixf/src/Sema/VariableLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ bool EnvNode::isLive() const {
void VariableLookupAnalysis::emitEnvLivenessWarning(
const std::shared_ptr<EnvNode> &NewEnv) {
for (const auto &[Name, Def] : NewEnv->defs()) {
// If the definition comes from lambda arg, omit the diagnostic
// because there is no elegant way to "fix" this trivially & keep
// the lambda signature.
if (Def->source() == Definition::DS_LambdaArg)
continue;
if (Def->uses().empty()) {
Diagnostic &D = Diags.emplace_back(Diagnostic::DK_DefinitionNotUsed,
Def->syntax()->range());
Expand Down
62 changes: 62 additions & 0 deletions nixd/tools/nixd/test/diagnostic-liveness-formal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# RUN: nixd --lit-test < %s | FileCheck %s

<-- initialize(0)

```json
{
"jsonrpc":"2.0",
"id":0,
"method":"initialize",
"params":{
"processId":123,
"rootPath":"",
"capabilities":{
},
"trace":"off"
}
}
```


<-- textDocument/didOpen

```json
{
"jsonrpc":"2.0",
"method":"textDocument/didOpen",
"params":{
"textDocument":{
"uri":"file:///basic.nix",
"languageId":"nix",
"version":1,
"text":"{x, y}: x + 1"
}
}
}
```

```
CHECK: "diagnostics": [
CHECK-NEXT: {
CHECK-NEXT: "code": "sema-def-not-used",
CHECK-NEXT: "message": "definition `y` is not used",
CHECK-NEXT: "range": {
CHECK-NEXT: "end": {
CHECK-NEXT: "character": 5,
CHECK-NEXT: "line": 0
CHECK-NEXT: },
CHECK-NEXT: "start": {
CHECK-NEXT: "character": 4,
CHECK-NEXT: "line": 0
CHECK-NEXT: }
CHECK-NEXT: },
CHECK-NEXT: "relatedInformation": [],
CHECK-NEXT: "severity": 2,
CHECK-NEXT: "source": "nixf",
CHECK-NEXT: "tags": [
CHECK-NEXT: 1
CHECK-NEXT: ]
CHECK-NEXT: }
CHECK-NEXT: ],
CHECK-NEXT: "uri": "file:///basic.nix",
```
23 changes: 1 addition & 22 deletions nixd/tools/nixd/test/diagnostic-liveness.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,7 @@
```

```
CHECK: "diagnostics": [
CHECK-NEXT: {
CHECK-NEXT: "code": "sema-def-not-used",
CHECK-NEXT: "message": "definition `y` is not used",
CHECK-NEXT: "range": {
CHECK-NEXT: "end": {
CHECK-NEXT: "character": 4,
CHECK-NEXT: "line": 0
CHECK-NEXT: },
CHECK-NEXT: "start": {
CHECK-NEXT: "character": 3,
CHECK-NEXT: "line": 0
CHECK-NEXT: }
CHECK-NEXT: },
CHECK-NEXT: "relatedInformation": [],
CHECK-NEXT: "severity": 2,
CHECK-NEXT: "source": "nixf",
CHECK-NEXT: "tags": [
CHECK-NEXT: 1
CHECK-NEXT: ]
CHECK-NEXT: }
CHECK-NEXT: ],
CHECK: "diagnostics": [],
CHECK-NEXT: "uri": "file:///basic.nix",
CHECK-NEXT: "version": 1
```

0 comments on commit 6748240

Please sign in to comment.