diff options
author | Ryan Lahfa <tvl@lahfa.xyz> | 2023-12-25T23·38+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-03T16·45+0000 |
commit | 743c3620491dba67ebeaf439a4f0073f97d5e0af (patch) | |
tree | 5db1c6bf1099b4a8815d4c6a19ff2397116e7edf /tvix/eval/src/value/mod.rs | |
parent | 802f374a90d8202785a34648c39aa6320ac171d9 (diff) |
feat(tvix/eval): context-aware `coerce_to_string` r/7317
I am still undecided whether we need a CoercionKind to control the coerced context, here's a simple attempt. Change-Id: Ibe59d09ef26c519a6acfdfe392014446646dd6d8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10426 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Autosubmit: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r-- | tvix/eval/src/value/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 16eb2a66b3fb..b688716d4131 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -318,15 +318,27 @@ impl Value { // Track if we are coercing the first value of a list to correctly emit // separating white spaces. let mut is_list_head = None; + // FIXME(raitobezarius): as per https://b.tvl.fyi/issues/364 + // we might be interested into more powerful context-related coercion kinds. + let mut context: NixContext = NixContext::new(); + loop { let value = if let Some(v) = vals.pop() { v.force(co, span.clone()).await? } else { - return Ok(Value::String(result.into())); + return Ok(Value::String(NixString::new_context_from( + context, + result.as_str(), + ))); }; let coerced = match (value, kind) { // coercions that are always done - (Value::String(s), _) => Ok(s.as_str().to_owned()), + (Value::String(mut s), _) => { + if let Some(ctx) = s.context_mut() { + context = context.join(ctx); + } + Ok(s.as_str().to_owned()) + } // TODO(sterni): Think about proper encoding handling here. This needs // general consideration anyways, since one current discrepancy between |