mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-31 12:30:32 +00:00
- Fixed erroneous "Return type mismatch error" when returning value of derived type
This commit is contained in:
parent
81010b4fbf
commit
f2202cca4f
1 changed files with 11 additions and 3 deletions
|
@ -92,6 +92,7 @@ static const FLOP FxFlops[] =
|
||||||
{ NAME_Round, FLOP_ROUND, [](double v) { return round(v); } },
|
{ NAME_Round, FLOP_ROUND, [](double v) { return round(v); } },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool AreCompatiblePointerTypes(PType* dest, PType* source, bool forcompare = false);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -149,9 +150,12 @@ void FCompileContext::CheckReturn(PPrototype *proto, FScriptPosition &pos)
|
||||||
// A prototype that defines fewer return types can be compatible with
|
// A prototype that defines fewer return types can be compatible with
|
||||||
// one that defines more if the shorter one matches the initial types
|
// one that defines more if the shorter one matches the initial types
|
||||||
// for the longer one.
|
// for the longer one.
|
||||||
|
bool swapped = false;
|
||||||
|
|
||||||
if (ReturnProto->ReturnTypes.Size() < proto->ReturnTypes.Size())
|
if (ReturnProto->ReturnTypes.Size() < proto->ReturnTypes.Size())
|
||||||
{ // Make proto the shorter one to avoid code duplication below.
|
{ // Make proto the shorter one to avoid code duplication below.
|
||||||
swapvalues(proto, ReturnProto);
|
swapvalues(proto, ReturnProto);
|
||||||
|
swapped = true;
|
||||||
}
|
}
|
||||||
// If one prototype returns nothing, they both must.
|
// If one prototype returns nothing, they both must.
|
||||||
if (proto->ReturnTypes.Size() == 0)
|
if (proto->ReturnTypes.Size() == 0)
|
||||||
|
@ -165,9 +169,13 @@ void FCompileContext::CheckReturn(PPrototype *proto, FScriptPosition &pos)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < proto->ReturnTypes.Size(); i++)
|
for (unsigned i = 0; i < proto->ReturnTypes.Size(); i++)
|
||||||
{
|
{
|
||||||
if (ReturnProto->ReturnTypes[i] != proto->ReturnTypes[i])
|
PType* expected = ReturnProto->ReturnTypes[i];
|
||||||
|
PType* actual = proto->ReturnTypes[i];
|
||||||
|
if (swapped) swapvalues(expected, actual);
|
||||||
|
|
||||||
|
if (expected != actual && !AreCompatiblePointerTypes(expected, actual))
|
||||||
{ // Incompatible
|
{ // Incompatible
|
||||||
Printf("Return type %s mismatch with %s\n", ReturnProto->ReturnTypes[i]->DescriptiveName(), proto->ReturnTypes[i]->DescriptiveName());
|
Printf("Return type %s mismatch with %s\n", expected->DescriptiveName(), actual->DescriptiveName());
|
||||||
fail = true;
|
fail = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +288,7 @@ static PFunction *FindBuiltinFunction(FName funcname)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
static bool AreCompatiblePointerTypes(PType *dest, PType *source, bool forcompare = false)
|
static bool AreCompatiblePointerTypes(PType *dest, PType *source, bool forcompare)
|
||||||
{
|
{
|
||||||
if (dest->isPointer() && source->isPointer())
|
if (dest->isPointer() && source->isPointer())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue