throw error on redefined record key

This commit is contained in:
Devyn Cairns 2024-07-06 02:57:07 -07:00
parent 2304d71941
commit 716d016a28
No known key found for this signature in database
2 changed files with 12 additions and 3 deletions

View File

@ -436,7 +436,16 @@ fn eval_instruction<D: DebugContext>(
let val = ctx.collect_reg(*val, *span)?;
let record_span = record_value.span();
let mut record = record_value.into_record()?;
record.insert(key.coerce_into_string()?, val);
let key = key.coerce_into_string()?;
if let Some(old_value) = record.insert(&key, val) {
return Err(ShellError::ColumnDefinedTwice {
col_name: key,
second_use: *span,
first_use: old_value.span(),
});
}
ctx.put_reg(
*src_dst,
Value::record(record, record_span).into_pipeline_data(),

View File

@ -150,8 +150,8 @@ pub enum Instruction {
ListPush { src_dst: RegId, item: RegId },
/// Spread a value onto the end of a list. Used to construct list literals.
ListSpread { src_dst: RegId, items: RegId },
/// Insert a key-value pair into a record. Used to construct record literals. Any existing value
/// for the key is overwritten.
/// Insert a key-value pair into a record. Used to construct record literals. Raises an error if
/// the key already existed in the record.
RecordInsert {
src_dst: RegId,
key: RegId,