mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-1296-fix-list-type-checks'
* origin/topic/jsiwek/gh-1296-fix-list-type-checks: GH-1296: fix type-checks related to list-type equality
This commit is contained in:
commit
7f3f5a868f
8 changed files with 116 additions and 39 deletions
52
src/Expr.cc
52
src/Expr.cc
|
@ -2651,19 +2651,28 @@ ValPtr AssignExpr::InitVal(const zeek::Type* t, ValPtr aggr) const
|
|||
|
||||
auto index = op1->InitVal(tt->GetIndices().get(), nullptr);
|
||||
|
||||
if ( ! same_type(*yt, *op2->GetType(), true) )
|
||||
if ( yt->Tag() == TYPE_RECORD )
|
||||
{
|
||||
if ( yt->Tag() == TYPE_RECORD && op2->GetType()->Tag() == TYPE_RECORD )
|
||||
if ( op2->GetType()->Tag() != TYPE_RECORD )
|
||||
{
|
||||
if ( ! record_promotion_compatible(yt->AsRecordType(),
|
||||
op2->GetType()->AsRecordType()) )
|
||||
{
|
||||
Error("type mismatch in table value initialization: "
|
||||
"incompatible record types");
|
||||
return nullptr;
|
||||
}
|
||||
Error(util::fmt("type mismatch in table value initialization: "
|
||||
"assigning '%s' to table with values of type '%s'",
|
||||
type_name(op2->GetType()->Tag()), type_name(yt->Tag())));
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
|
||||
if ( ! same_type(*yt, *op2->GetType()) &&
|
||||
! record_promotion_compatible(yt->AsRecordType(),
|
||||
op2->GetType()->AsRecordType()) )
|
||||
{
|
||||
Error("type mismatch in table value initialization: "
|
||||
"incompatible record types");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! same_type(*yt, *op2->GetType(), true) )
|
||||
{
|
||||
Error(util::fmt("type mismatch in table value initialization: "
|
||||
"assigning '%s' to table with values of type '%s'",
|
||||
|
@ -4143,29 +4152,6 @@ InExpr::InExpr(ExprPtr arg_op1, ExprPtr arg_op2)
|
|||
SetType(base_type(TYPE_BOOL));
|
||||
}
|
||||
|
||||
else if ( op1->GetType()->Tag() == TYPE_RECORD )
|
||||
{
|
||||
if ( op2->GetType()->Tag() != TYPE_TABLE )
|
||||
{
|
||||
op2->GetType()->Error("table/set required");
|
||||
SetError();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
const auto& t1 = op1->GetType();
|
||||
const auto& it = op2->GetType()->AsTableType()->GetIndices();
|
||||
|
||||
if ( ! same_type(t1, it) )
|
||||
{
|
||||
t1->Error("indexing mismatch", op2->GetType().get());
|
||||
SetError();
|
||||
}
|
||||
else
|
||||
SetType(base_type(TYPE_BOOL));
|
||||
}
|
||||
}
|
||||
|
||||
else if ( op1->GetType()->Tag() == TYPE_STRING &&
|
||||
op2->GetType()->Tag() == TYPE_STRING )
|
||||
SetType(base_type(TYPE_BOOL));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue