From 210737f36e3cf026057ab9e7c2233ecb0bad46f8 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Sun, 21 Sep 2025 17:13:14 +0000 Subject: [PATCH] Restore the SetType constructor and destructor --- src/Type.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/Type.cc b/src/Type.cc index 5e343ed47a..397a27ebe8 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -569,6 +569,50 @@ bool TableType::DoExpireCheck(const detail::AttrPtr& attr) { return true; } +SetType::SetType(TypeListPtr ind, detail::ListExprPtr arg_elements) + : TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) { + if ( elements ) { + if ( indices ) { // We already have a type. + if ( ! check_and_promote_exprs(elements.get(), indices) ) + SetError(); + } + else { + TypeList* tl_type = elements->GetType()->AsTypeList(); + const auto& tl = tl_type->GetTypes(); + + if ( tl.size() < 1 ) { + Error("no type given for set"); + SetError(); + } + + else if ( tl.size() == 1 ) { + TypePtr ft{NewRef{}, flatten_type(tl[0].get())}; + indices = make_intrusive(ft); + indices->Append(std::move(ft)); + } + + else { + auto t = merge_types(tl[0], tl[1]); + + for ( size_t i = 2; t && i < tl.size(); ++i ) + t = merge_types(t, tl[i]); + + if ( ! t ) { + Error("bad set type"); + return; + } + + indices = make_intrusive(t); + indices->Append(std::move(t)); + } + } + } +} + +TypePtr SetType::ShallowClone() { return make_intrusive(indices, elements); } + +SetType::~SetType() = default; + FuncType::Capture::Capture(detail::IDPtr _id, bool _deep_copy) : id(std::move(_id)), deep_copy(_deep_copy) { is_managed = id ? ZVal::IsManagedType(id->GetType()) : false; if ( ! is_managed )