mirror of
https://github.com/zeek/zeek.git
synced 2025-10-01 22:28:20 +00:00
Merge remote-tracking branch 'origin/topic/vern/id-redecl'
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
* origin/topic/vern/id-redecl: fixes for re-declaring type identifiers in inconsistent ways - addresses GH-2686
This commit is contained in:
commit
8b4707a284
6 changed files with 46 additions and 1 deletions
4
CHANGES
4
CHANGES
|
@ -1,3 +1,7 @@
|
|||
8.1.0-dev.621 | 2025-09-30 20:46:27 +0000
|
||||
|
||||
* GH-2686: fixes for re-declaring type identifiers in inconsistent ways - addresses GH-2686 (Vern Paxson, Corelight)
|
||||
|
||||
8.1.0-dev.619 | 2025-09-30 20:45:19 +0000
|
||||
|
||||
* Fix for standalone initializations that require BiFs, and streamlining of standalone BiF-tracking (Vern Paxson, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
8.1.0-dev.619
|
||||
8.1.0-dev.621
|
||||
|
|
29
src/Var.cc
29
src/Var.cc
|
@ -348,6 +348,35 @@ 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, or an equivalent enum.
|
||||
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 && same_type(t, old_t))) )
|
||||
// It has a consistent tag and is either redeclaring a stub
|
||||
// record (used in init-bare.zeek) or an equivalent enum
|
||||
// (which can appear due to specifiers in BiFs, for example).
|
||||
;
|
||||
|
||||
else {
|
||||
std::string loc;
|
||||
auto li = id->GetLocationInfo();
|
||||
auto fn = li->FileName();
|
||||
int ln = li->FirstLine();
|
||||
if ( fn && fn[0] != '\0' )
|
||||
loc = " at " + std::string(fn) + ":" + std::to_string(ln);
|
||||
|
||||
reporter->Error("Type %s has already been declared%s", id->Name(), loc.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::string new_type_name = id->Name();
|
||||
std::string old_type_name = t->GetName();
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/redeclaration-redefinition-errors.zeek, line 2: Identifier f has already been declared and is not a type
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/redeclaration-redefinition-errors.zeek, line 2: Type f has already been declared at <...>/redeclaration-redefinition-errors.zeek:1
|
|
@ -59,3 +59,11 @@ global f: function();
|
|||
global f = function() { };
|
||||
global f: hook();
|
||||
global f: event();
|
||||
|
||||
# @TEST-START-NEXT
|
||||
global f = function() { };
|
||||
type f: bool;
|
||||
|
||||
# @TEST-START-NEXT
|
||||
type f: record {};
|
||||
type f: bool;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue