fix(tvix/eval): determine meaning of +
exprs based on first type
This matches the behavior of C++ Nix more closely where the decision is
made based on the first type based to ExprConcatStrings:
1f93fa2ed2/src/libexpr/eval.cc (L1967-L2025)
Note that this doesn't make a difference in any successful
evaluation (at least to my knowledge), but ensures that our error
messages will match C++ Nix more closely, e.g. in the case of
`1 + "string"`.
Change-Id: I8059930788f9c8d98baf98e3d93d8a060ef961f2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10360
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: Adam Joseph <adam@westernsemico.com>
This commit is contained in:
parent
8b0047e277
commit
a30dd0905a
1 changed files with 11 additions and 5 deletions
|
@ -1202,6 +1202,7 @@ async fn resolve_with(
|
||||||
|
|
||||||
// TODO(amjoseph): de-asyncify this
|
// TODO(amjoseph): de-asyncify this
|
||||||
async fn add_values(co: GenCo, a: Value, b: Value) -> Result<Value, ErrorKind> {
|
async fn add_values(co: GenCo, a: Value, b: Value) -> Result<Value, ErrorKind> {
|
||||||
|
// What we try to do is solely determined by the type of the first value!
|
||||||
let result = match (a, b) {
|
let result = match (a, b) {
|
||||||
(Value::Path(p), v) => {
|
(Value::Path(p), v) => {
|
||||||
let mut path = p.to_string_lossy().into_owned();
|
let mut path = p.to_string_lossy().into_owned();
|
||||||
|
@ -1218,11 +1219,16 @@ async fn add_values(co: GenCo, a: Value, b: Value) -> Result<Value, ErrorKind> {
|
||||||
.await
|
.await
|
||||||
.map(|s2| Value::String(s1.concat(&s2)))
|
.map(|s2| Value::String(s1.concat(&s2)))
|
||||||
.into(),
|
.into(),
|
||||||
(v, Value::String(s2)) => generators::request_string_coerce(&co, v, CoercionKind::Weak)
|
(a @ Value::Integer(_), b) | (a @ Value::Float(_), b) => arithmetic_op!(&a, &b, +)?,
|
||||||
.await
|
(a, b) => {
|
||||||
.map(|s1| Value::String(s1.concat(&s2)))
|
let r1 = generators::request_string_coerce(&co, a, CoercionKind::Weak).await;
|
||||||
.into(),
|
let r2 = generators::request_string_coerce(&co, b, CoercionKind::Weak).await;
|
||||||
(a, b) => arithmetic_op!(&a, &b, +)?,
|
match (r1, r2) {
|
||||||
|
(Ok(s1), Ok(s2)) => Value::String(s1.concat(&s2)),
|
||||||
|
(Err(c), _) => return Ok(Value::Catchable(c)),
|
||||||
|
(_, Err(c)) => return Ok(Value::Catchable(c)),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|
Loading…
Reference in a new issue