importing fix for redeclaring variables

This commit is contained in:
Vern Paxson 2025-09-27 16:47:11 -07:00
parent 76bf845ec8
commit 2efa5cd075

View file

@ -348,6 +348,28 @@ extern ExprPtr add_and_assign_local(IDPtr id, ExprPtr init, ValPtr val) {
}
void add_type(ID* id, TypePtr t, std::unique_ptr<std::vector<AttrPtr>> attr) {
if ( const auto& old_t = id->GetType() ) {
// The identifier already has a type associated with it. This can
// be okay if (1) it's already been marked as a Type identifier,
// (2) the previous type is a stub.
if ( ! id->IsType() ) {
reporter->Error("Identifier %s has already been declared and is not a type", id->Name());
return;
}
if ( old_t->Tag() == t->Tag() &&
((old_t->Tag() == TYPE_RECORD && old_t->AsRecordType()->NumFields() == 0) || t->Tag() == TYPE_ENUM) )
// It has a consistent tag and is either redeclaring a stub
// record (used in init-bare.zeek) or an enum (which can
// appear due to specifiers in BiFs, for example).
;
else {
reporter->Error("Type %s has already been declared", id->Name());
return;
}
}
std::string new_type_name = id->Name();
std::string old_type_name = t->GetName();