diff --git a/src/Val.cc b/src/Val.cc index 4247d437e1..c1fdaae833 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2936,7 +2936,8 @@ void RecordVal::ResizeParseTimeRecords(RecordType* revised_rt) if ( required_length > current_length ) { for ( auto i = current_length; i < required_length; ++i ) - rv->AppendField(revised_rt->FieldDefault(i)); + rv->AppendField(revised_rt->FieldDefault(i), + revised_rt->GetFieldType(i)); } } } @@ -3123,7 +3124,7 @@ ValPtr RecordVal::DoClone(CloneState* state) { auto f_i = GetField(i); auto v = f_i ? f_i->Clone(state) : nullptr; - rv->AppendField(std::move(v)); + rv->AppendField(std::move(v), rt->GetFieldType(i)); } return rv; diff --git a/src/Val.h b/src/Val.h index 70b044f9b6..97131f8d00 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1176,13 +1176,15 @@ public: /** * Appends a value to the record's fields. The caller is responsible * for ensuring that fields are appended in the correct order and - * with the correct type. + * with the correct type. The type needs to be passed in because + * it's unsafe to take it from v when the field's type is "any" while + * v is a concrete type. * @param v The value to append. */ - void AppendField(ValPtr v) + void AppendField(ValPtr v, const TypePtr& t) { if ( v ) - record_val->emplace_back(ZVal(v, v->GetType())); + record_val->emplace_back(ZVal(v, t)); else record_val->emplace_back(std::nullopt); }