mirror of
https://github.com/zeek/zeek.git
synced 2025-10-16 13:38:19 +00:00
types: Fix table() resulting in table_type->IsSet() == true
typename(table()) apparently always resulted in a set[] type being rendered. Make the yield type of an unspecified table ANY so that type->IsSet() ends up false. While at it, also render unspecified types as table(), set() and vector() rather than vector of void, set[] or table[] of any which IMO should help to figure out what's going.
This commit is contained in:
parent
e4dbba20a4
commit
189565d131
4 changed files with 27 additions and 3 deletions
|
@ -3181,7 +3181,7 @@ TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list,
|
|||
}
|
||||
else {
|
||||
if ( op->AsListExpr()->Exprs().empty() )
|
||||
SetType(make_intrusive<TableType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), nullptr));
|
||||
SetType(make_intrusive<TableType>(make_intrusive<TypeList>(base_type(TYPE_ANY)), base_type(TYPE_ANY)));
|
||||
else {
|
||||
SetType(init_type(op));
|
||||
|
||||
|
|
17
src/Type.cc
17
src/Type.cc
|
@ -320,11 +320,19 @@ int IndexType::MatchesIndex(detail::ListExpr* const index) const {
|
|||
|
||||
void IndexType::DoDescribe(ODesc* d) const {
|
||||
Type::DoDescribe(d);
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("[");
|
||||
|
||||
const auto& its = GetIndexTypes();
|
||||
|
||||
// Deal with unspecified table/set.
|
||||
if ( its.empty() ) {
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("()");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! d->IsBinary() )
|
||||
d->Add("[");
|
||||
|
||||
for ( auto i = 0u; i < its.size(); ++i ) {
|
||||
if ( ! d->IsBinary() && i > 0 )
|
||||
d->Add(",");
|
||||
|
@ -1763,6 +1771,11 @@ int VectorType::MatchesIndex(detail::ListExpr* const index) const {
|
|||
bool VectorType::IsUnspecifiedVector() const { return yield_type->Tag() == TYPE_VOID; }
|
||||
|
||||
void VectorType::DoDescribe(ODesc* d) const {
|
||||
if ( IsUnspecifiedVector() && d->IsReadable() ) {
|
||||
d->Add("vector()");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( d->IsReadable() )
|
||||
d->AddSP("vector of");
|
||||
else
|
||||
|
|
4
testing/btest/Baseline/language.unspecified/output
Normal file
4
testing/btest/Baseline/language.unspecified/output
Normal file
|
@ -0,0 +1,4 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
set()
|
||||
table()
|
||||
vector()
|
7
testing/btest/language/unspecified.zeek
Normal file
7
testing/btest/language/unspecified.zeek
Normal file
|
@ -0,0 +1,7 @@
|
|||
# @TEST-DOC: Test representation of unspecified table, set and vector
|
||||
# @TEST-EXEC: zeek -b %INPUT >output
|
||||
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output
|
||||
|
||||
print type_name(set());
|
||||
print type_name(table());
|
||||
print type_name(vector());
|
Loading…
Add table
Add a link
Reference in a new issue