Use switch statement instead of sequence of ifs

This commit is contained in:
Danila Fedorin 2021-01-08 03:13:42 +00:00
parent 93f1678ec6
commit ba0f841a07

View file

@ -120,15 +120,19 @@ static FlakeInput parseFlakeInput(EvalState & state,
expectType(state, nString, *attr.value, *attr.pos); expectType(state, nString, *attr.value, *attr.pos);
input.follows = parseInputPath(attr.value->string.s); input.follows = parseInputPath(attr.value->string.s);
} else { } else {
if (attr.value->type() == nString) { switch (attr.value->type()) {
attrs.emplace(attr.name, attr.value->string.s); case nString:
} else if (attr.value->type() == nBool) { attrs.emplace(attr.name, attr.value->string.s);
attrs.emplace(attr.name, Explicit<bool>{ attr.value->boolean }); break;
} else if (attr.value->type() == nInt) { case nBool:
attrs.emplace(attr.name, attr.value->integer); attrs.emplace(attr.name, Explicit<bool> { attr.value->boolean });
} else { break;
throw TypeError("flake input attribute '%s' is %s while a string, boolean, or integer is expected", case nInt:
attr.name, showType(*attr.value)); attrs.emplace(attr.name, attr.value->integer);
break;
default:
throw TypeError("flake input attribute '%s' is %s while a string, boolean, or integer is expected",
attr.name, showType(*attr.value));
} }
} }
} catch (Error & e) { } catch (Error & e) {