fixes for vector assignments involving "any"/"vector of any" types

This commit is contained in:
Vern Paxson 2023-08-24 15:48:00 -07:00
parent ae03d591b8
commit d70a0fae85
2 changed files with 7 additions and 3 deletions

View file

@ -814,7 +814,8 @@ ValPtr BinaryExpr::Fold(Val* v1, Val* v2) const
if ( t1->Tag() == TYPE_VECTOR ) if ( t1->Tag() == TYPE_VECTOR )
{ {
// We only get here when using a matching vector on the RHS. // We only get here when using a matching vector on the RHS.
v2->AsVectorVal()->AddTo(v1, false); if ( ! v2->AsVectorVal()->AddTo(v1, false) )
Error("incompatible vector element assignment", v2);
return {NewRef{}, v1}; return {NewRef{}, v1};
} }
@ -1683,7 +1684,9 @@ AddToExpr::AddToExpr(ExprPtr arg_op1, ExprPtr arg_op2)
else if ( IsVector(bt1) ) else if ( IsVector(bt1) )
{ {
if ( same_type(t1, t2) ) // We need the IsVector(bt2) check in the following because
// same_type() always treats "any" types as "same".
if ( IsVector(bt2) && same_type(t1, t2) )
{ {
SetType(t1); SetType(t1);
return; return;

View file

@ -3726,7 +3726,8 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const
auto last_idx = v->Size(); auto last_idx = v->Size();
for ( auto i = 0u; i < Size(); ++i ) for ( auto i = 0u; i < Size(); ++i )
v->Assign(last_idx++, At(i)); if ( ! v->Assign(last_idx++, At(i)) )
return false;
return true; return true;
} }