- fix missing type check when using Push or Insert for typed arrays

This commit is contained in:
Magnus Norddahl 2018-11-14 10:08:04 +01:00
parent a6b44b02b7
commit 8429fc8124
2 changed files with 15 additions and 0 deletions

View file

@ -896,6 +896,8 @@ xx(DamageFunction)
xx(Length) xx(Length)
xx(Unit) xx(Unit)
xx(Size) xx(Size)
xx(Push)
xx(Insert)
xx(Copy) xx(Copy)
xx(Move) xx(Move)
xx(Voidptr) xx(Voidptr)

View file

@ -8240,7 +8240,9 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
{ {
auto elementType = static_cast<PDynArray*>(Self->ValueType)->ElementType; auto elementType = static_cast<PDynArray*>(Self->ValueType)->ElementType;
Self->ValueType = static_cast<PDynArray*>(Self->ValueType)->BackingType; Self->ValueType = static_cast<PDynArray*>(Self->ValueType)->BackingType;
bool isDynArrayObj = elementType->isObjectPointer();
// this requires some added type checks for the passed types. // this requires some added type checks for the passed types.
int idx = 0;
for (auto &a : ArgList) for (auto &a : ArgList)
{ {
a = a->Resolve(ctx); a = a->Resolve(ctx);
@ -8249,6 +8251,16 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
delete this; delete this;
return nullptr; return nullptr;
} }
if (isDynArrayObj && ((MethodName == NAME_Push && idx == 0) || (MethodName == NAME_Insert && idx == 1)))
{
// The DynArray_Obj declaration in dynarrays.txt doesn't support generics yet. Check the type here as if it did.
if (!static_cast<PObjectPointer*>(elementType)->PointedClass()->IsAncestorOf(static_cast<PObjectPointer*>(a->ValueType)->PointedClass()))
{
ScriptPosition.Message(MSG_ERROR, "Type mismatch in function argument");
delete this;
return nullptr;
}
}
if (a->IsDynamicArray()) if (a->IsDynamicArray())
{ {
// Copy and Move must turn their parameter into a pointer to the backing struct type. // Copy and Move must turn their parameter into a pointer to the backing struct type.
@ -8288,6 +8300,7 @@ FxExpression *FxMemberFunctionCall::Resolve(FCompileContext& ctx)
return nullptr; return nullptr;
} }
} }
idx++;
} }
} }
} }