mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
GH-1344: Give better warning when using a type that doesn't exist
This commit is contained in:
parent
6d16f9bb42
commit
8e4017f781
3 changed files with 23 additions and 0 deletions
11
src/Var.cc
11
src/Var.cc
|
@ -429,14 +429,25 @@ void add_type(ID* id, TypePtr t, std::unique_ptr<std::vector<AttrPtr>> attr)
|
|||
{
|
||||
std::string new_type_name = id->Name();
|
||||
std::string old_type_name = t->GetName();
|
||||
|
||||
TypePtr tnew;
|
||||
|
||||
if ( (t->Tag() == TYPE_RECORD || t->Tag() == TYPE_ENUM) && old_type_name.empty() )
|
||||
// An extensible type (record/enum) being declared for first time.
|
||||
tnew = std::move(t);
|
||||
else
|
||||
{
|
||||
// If the old type is an error or the old type doesn't exist, then return
|
||||
// an error instead of trying to clone it.
|
||||
if ( t->Tag() == TYPE_ERROR && t->InternalType() == TYPE_INTERNAL_ERROR )
|
||||
{
|
||||
reporter->Error("Error trying to create alias to nonexistent type");
|
||||
return;
|
||||
}
|
||||
|
||||
// Clone the type to preserve type name aliasing.
|
||||
tnew = t->ShallowClone();
|
||||
}
|
||||
|
||||
Type::RegisterAlias(new_type_name, tnew);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue