mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 11:08:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/gh-594-improve-table-init-type-checking'
* origin/topic/jsiwek/gh-594-improve-table-init-type-checking: GH-594: Improve table initialization type-check error messages
This commit is contained in:
commit
60443e3178
5 changed files with 54 additions and 1 deletions
22
src/Expr.cc
22
src/Expr.cc
|
@ -2433,6 +2433,28 @@ ValPtr AssignExpr::InitVal(const zeek::Type* t, ValPtr aggr) const
|
|||
const auto& yt = tv->GetType()->Yield();
|
||||
|
||||
auto index = op1->InitVal(tt->GetIndices().get(), nullptr);
|
||||
|
||||
if ( ! same_type(*yt, *op2->GetType(), true) )
|
||||
{
|
||||
if ( yt->Tag() == TYPE_RECORD && 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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(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;
|
||||
}
|
||||
}
|
||||
|
||||
auto v = op2->InitVal(yt.get(), nullptr);
|
||||
|
||||
if ( ! index || ! v )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue