throw error on redefined record key
This commit is contained in:
parent
2304d71941
commit
716d016a28
|
@ -436,7 +436,16 @@ fn eval_instruction<D: DebugContext>(
|
||||||
let val = ctx.collect_reg(*val, *span)?;
|
let val = ctx.collect_reg(*val, *span)?;
|
||||||
let record_span = record_value.span();
|
let record_span = record_value.span();
|
||||||
let mut record = record_value.into_record()?;
|
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(
|
ctx.put_reg(
|
||||||
*src_dst,
|
*src_dst,
|
||||||
Value::record(record, record_span).into_pipeline_data(),
|
Value::record(record, record_span).into_pipeline_data(),
|
||||||
|
|
|
@ -150,8 +150,8 @@ pub enum Instruction {
|
||||||
ListPush { src_dst: RegId, item: RegId },
|
ListPush { src_dst: RegId, item: RegId },
|
||||||
/// Spread a value onto the end of a list. Used to construct list literals.
|
/// Spread a value onto the end of a list. Used to construct list literals.
|
||||||
ListSpread { src_dst: RegId, items: RegId },
|
ListSpread { src_dst: RegId, items: RegId },
|
||||||
/// Insert a key-value pair into a record. Used to construct record literals. Any existing value
|
/// Insert a key-value pair into a record. Used to construct record literals. Raises an error if
|
||||||
/// for the key is overwritten.
|
/// the key already existed in the record.
|
||||||
RecordInsert {
|
RecordInsert {
|
||||||
src_dst: RegId,
|
src_dst: RegId,
|
||||||
key: RegId,
|
key: RegId,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user