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:
Arne Welzel 2024-11-06 12:25:19 +01:00
parent e4dbba20a4
commit 189565d131
4 changed files with 27 additions and 3 deletions

View file

@ -3181,7 +3181,7 @@ TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list,
} }
else { else {
if ( op->AsListExpr()->Exprs().empty() ) 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 { else {
SetType(init_type(op)); SetType(init_type(op));

View file

@ -320,11 +320,19 @@ int IndexType::MatchesIndex(detail::ListExpr* const index) const {
void IndexType::DoDescribe(ODesc* d) const { void IndexType::DoDescribe(ODesc* d) const {
Type::DoDescribe(d); Type::DoDescribe(d);
if ( ! d->IsBinary() )
d->Add("[");
const auto& its = GetIndexTypes(); 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 ) { for ( auto i = 0u; i < its.size(); ++i ) {
if ( ! d->IsBinary() && i > 0 ) if ( ! d->IsBinary() && i > 0 )
d->Add(","); d->Add(",");
@ -1763,6 +1771,11 @@ int VectorType::MatchesIndex(detail::ListExpr* const index) const {
bool VectorType::IsUnspecifiedVector() const { return yield_type->Tag() == TYPE_VOID; } bool VectorType::IsUnspecifiedVector() const { return yield_type->Tag() == TYPE_VOID; }
void VectorType::DoDescribe(ODesc* d) const { void VectorType::DoDescribe(ODesc* d) const {
if ( IsUnspecifiedVector() && d->IsReadable() ) {
d->Add("vector()");
return;
}
if ( d->IsReadable() ) if ( d->IsReadable() )
d->AddSP("vector of"); d->AddSP("vector of");
else else

View 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()

View 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());