refactor(tvix): remove signedness conversions by using std::optional
The different signedness of level and withLevel was causing implicit conversions. Use a nullopt instead of a -1 sentinel value. third_party/nix/src/libexpr/nixexpr.cc:242:21: warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [bugprone-narrowing-conversions] Change-Id: I7c2cadb6fd6bbff6c5b84028651ad4ebba423297 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2157 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in> Reviewed-by: glittershark <grfn@gws.fyi>
This commit is contained in:
parent
5fb58e23de
commit
0c8c1227f1
1 changed files with 4 additions and 4 deletions
8
third_party/nix/src/libexpr/nixexpr.cc
vendored
8
third_party/nix/src/libexpr/nixexpr.cc
vendored
|
@ -234,11 +234,11 @@ void ExprVar::bindVars(const StaticEnv& env) {
|
||||||
set its level and displacement. */
|
set its level and displacement. */
|
||||||
const StaticEnv* curEnv;
|
const StaticEnv* curEnv;
|
||||||
unsigned int level;
|
unsigned int level;
|
||||||
int withLevel = -1;
|
std::optional<unsigned int> withLevel = std::nullopt;
|
||||||
for (curEnv = &env, level = 0; curEnv != nullptr;
|
for (curEnv = &env, level = 0; curEnv != nullptr;
|
||||||
curEnv = curEnv->up, level++) {
|
curEnv = curEnv->up, level++) {
|
||||||
if (curEnv->isWith) {
|
if (curEnv->isWith) {
|
||||||
if (withLevel == -1) {
|
if (!withLevel.has_value()) {
|
||||||
withLevel = level;
|
withLevel = level;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -255,13 +255,13 @@ void ExprVar::bindVars(const StaticEnv& env) {
|
||||||
/* Otherwise, the variable must be obtained from the nearest
|
/* Otherwise, the variable must be obtained from the nearest
|
||||||
enclosing `with'. If there is no `with', then we can issue an
|
enclosing `with'. If there is no `with', then we can issue an
|
||||||
"undefined variable" error now. */
|
"undefined variable" error now. */
|
||||||
if (withLevel == -1) {
|
if (!withLevel.has_value()) {
|
||||||
throw UndefinedVarError(format("undefined variable '%1%' at %2%") % name %
|
throw UndefinedVarError(format("undefined variable '%1%' at %2%") % name %
|
||||||
pos);
|
pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
fromWith = true;
|
fromWith = true;
|
||||||
this->level = withLevel;
|
this->level = withLevel.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExprSelect::bindVars(const StaticEnv& env) {
|
void ExprSelect::bindVars(const StaticEnv& env) {
|
||||||
|
|
Loading…
Reference in a new issue