mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
GH-2920: Don't warn on uninitialized container options
This commit is contained in:
parent
c5ce82143a
commit
fcf7af259c
6 changed files with 46 additions and 2 deletions
|
@ -1024,7 +1024,7 @@ inline bool IsString(TypeTag t)
|
||||||
return (t == TYPE_STRING);
|
return (t == TYPE_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// True if the given type is a container aggregate.
|
// True if the given type is an aggregate.
|
||||||
inline bool IsAggr(TypeTag tag)
|
inline bool IsAggr(TypeTag tag)
|
||||||
{
|
{
|
||||||
return tag == TYPE_VECTOR || tag == TYPE_TABLE || tag == TYPE_RECORD;
|
return tag == TYPE_VECTOR || tag == TYPE_TABLE || tag == TYPE_RECORD;
|
||||||
|
@ -1038,6 +1038,12 @@ inline bool IsAggr(const TypePtr& t)
|
||||||
return IsAggr(t->Tag());
|
return IsAggr(t->Tag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// True if the given type is a container.
|
||||||
|
inline bool IsContainer(TypeTag tag)
|
||||||
|
{
|
||||||
|
return tag == TYPE_VECTOR || tag == TYPE_TABLE;
|
||||||
|
}
|
||||||
|
|
||||||
// True if the given type tag corresponds to the error type.
|
// True if the given type tag corresponds to the error type.
|
||||||
inline bool IsErrorType(TypeTag t)
|
inline bool IsErrorType(TypeTag t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -381,7 +381,7 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init,
|
||||||
|
|
||||||
if ( dt == VAR_OPTION )
|
if ( dt == VAR_OPTION )
|
||||||
{
|
{
|
||||||
if ( ! init )
|
if ( ! init && ! IsContainer(t->Tag()) )
|
||||||
id->Error("option variable must be initialized");
|
id->Error("option variable must be initialized");
|
||||||
|
|
||||||
id->SetOption();
|
id->SetOption();
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
1
testing/btest/Baseline/language.record-option-init/out
Normal file
1
testing/btest/Baseline/language.record-option-init/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
14
testing/btest/language/container-option-init.zeek
Normal file
14
testing/btest/language/container-option-init.zeek
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Ensures that an error doesn't print out for option variables
|
||||||
|
# that are containers. These get automatically initialized so
|
||||||
|
# there's no need to manually initialize them.
|
||||||
|
|
||||||
|
# @TEST-EXEC: zeek -b %INPUT > out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
option foo: set[count] &redef;
|
||||||
|
option foo2: table[count] of count &redef;
|
||||||
|
option foo3: vector of count &redef;
|
||||||
|
|
||||||
|
print |foo|;
|
||||||
|
print |foo2|;
|
||||||
|
print |foo3|;
|
19
testing/btest/language/record-option-init.zeek
Normal file
19
testing/btest/language/record-option-init.zeek
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Ensures that an error is printed out for option variables
|
||||||
|
# that are containers if they aren't initialized.
|
||||||
|
|
||||||
|
# @TEST-EXEC-FAIL: zeek -b %INPUT > out
|
||||||
|
# @TEST-EXEC: btest-diff out
|
||||||
|
|
||||||
|
@load misc/stats
|
||||||
|
|
||||||
|
type TestRecord: record {
|
||||||
|
a: count;
|
||||||
|
b: Stats::Info &optional;
|
||||||
|
};
|
||||||
|
|
||||||
|
option foo: TestRecord &redef;
|
||||||
|
|
||||||
|
event zeek_init()
|
||||||
|
{
|
||||||
|
print foo;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue