feat(tvix/eval): warn on empty let-bindings
Change-Id: Ib6ef7ce514abbd3e372dfe9df7137aa36dbda9d4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7770 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
61b8a9b2ba
commit
aadf71a6ed
2 changed files with 10 additions and 1 deletions
|
@ -647,6 +647,9 @@ impl Compiler<'_> {
|
||||||
self.emit_constant(Value::Attrs(Box::new(NixAttrs::empty())), node);
|
self.emit_constant(Value::Attrs(Box::new(NixAttrs::empty())), node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.emit_warning(node, WarningKind::EmptyLet);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actually bind values and ensure they are on the stack.
|
// Actually bind values and ensure they are on the stack.
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub enum WarningKind {
|
||||||
UselessBoolOperation(&'static str),
|
UselessBoolOperation(&'static str),
|
||||||
DeadCode,
|
DeadCode,
|
||||||
EmptyInherit,
|
EmptyInherit,
|
||||||
|
EmptyLet,
|
||||||
|
|
||||||
/// Tvix internal warning for features triggered by users that are
|
/// Tvix internal warning for features triggered by users that are
|
||||||
/// not actually implemented yet, but do not cause runtime failures.
|
/// not actually implemented yet, but do not cause runtime failures.
|
||||||
|
@ -66,7 +67,7 @@ impl EvalWarning {
|
||||||
}
|
}
|
||||||
|
|
||||||
WarningKind::UselessInherit => {
|
WarningKind::UselessInherit => {
|
||||||
"inherited variable already exists with the same value".to_string()
|
format!("inherit does nothing (this variable already exists with the same value)")
|
||||||
}
|
}
|
||||||
|
|
||||||
WarningKind::UnusedBinding => {
|
WarningKind::UnusedBinding => {
|
||||||
|
@ -100,6 +101,10 @@ impl EvalWarning {
|
||||||
format!("this `inherit` statement is empty")
|
format!("this `inherit` statement is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WarningKind::EmptyLet => {
|
||||||
|
format!("this `let`-expression contains no bindings")
|
||||||
|
}
|
||||||
|
|
||||||
WarningKind::NotImplemented(what) => {
|
WarningKind::NotImplemented(what) => {
|
||||||
format!("feature not yet implemented in tvix: {}", what)
|
format!("feature not yet implemented in tvix: {}", what)
|
||||||
}
|
}
|
||||||
|
@ -119,6 +124,7 @@ impl EvalWarning {
|
||||||
WarningKind::UselessBoolOperation(_) => "W007",
|
WarningKind::UselessBoolOperation(_) => "W007",
|
||||||
WarningKind::DeadCode => "W008",
|
WarningKind::DeadCode => "W008",
|
||||||
WarningKind::EmptyInherit => "W009",
|
WarningKind::EmptyInherit => "W009",
|
||||||
|
WarningKind::EmptyLet => "W010",
|
||||||
|
|
||||||
WarningKind::NotImplemented(_) => "W999",
|
WarningKind::NotImplemented(_) => "W999",
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue