Skip to content

Commit 47a0ded

Browse files
committed
usage: add string exception for attrpaths
Fixes Github issue #91
1 parent be32f41 commit 47a0ded

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/dead_code_tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,24 @@ fn let_partially_shadowed_by_attrset() {
461461
assert_eq!(1, results.len());
462462
assert_eq!(results[0].binding.name.to_string(), "dead");
463463
}
464+
465+
#[test]
466+
fn let_args_splice() {
467+
let results = run("
468+
{ config, ... }:
469+
470+
\"${config.bar}\"
471+
");
472+
assert_eq!(0, results.len());
473+
}
474+
475+
#[test]
476+
fn let_args_string_splice() {
477+
let results = run("
478+
{ config, ... }: {
479+
480+
\"${config.bar}\" = 42;
481+
}
482+
");
483+
assert_eq!(0, results.len());
484+
}

src/usage.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ pub fn find(name: &Ident, node: &SyntaxNode<NixLanguage>) -> bool {
2727
ident.syntax().text() == name.syntax().text()
2828
} else if node.kind() == SyntaxKind::NODE_ATTRPATH {
2929
// Don't search for idents in keys, they introduce new scopes
30-
// anyway. Except for `${...}`
30+
// anyway. Except for `${...}` and `"..."` which do not
31+
// introduce new scopes in attrsets that are not declared
32+
// `rec`.
3133
node.children().any(|node|
32-
node.kind() == SyntaxKind::NODE_DYNAMIC &&
34+
(node.kind() == SyntaxKind::NODE_DYNAMIC ||
35+
node.kind() == SyntaxKind::NODE_STRING
36+
) &&
3337
find(name, &node)
3438
)
3539
} else {

0 commit comments

Comments
 (0)