Fix auto deduction of void return type

This commit is contained in:
drmortalwombat 2024-05-25 22:25:59 +02:00
parent b1b5ee737b
commit 13629c70d4
2 changed files with 52 additions and 37 deletions

View File

@ -4328,12 +4328,24 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vr = Dereference(proc, exp, block, inlineMapper, vr);
if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID)
{
if (vr.mType->mType != DT_TYPE_VOID)
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has void return type");
}
else if (procType->mBase->mType == DT_TYPE_BOOL && (vr.mType->IsIntegerType() || vr.mType->mType == DT_TYPE_POINTER))
;
else if (!procType->mBase->CanAssign(vr.mType))
mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Cannot return incompatible type");
if (vr.mType->mType == DT_TYPE_VOID)
{
if (inlineMapper)
ins->mCode = IC_NONE;
else
ins->mCode = IC_RETURN;
}
else
{
vr = CoerceType(proc, exp, block, inlineMapper, vr, procType->mBase);
ins->mSrc[0].mType = InterTypeOf(vr.mType);
@ -4375,7 +4387,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
ins->mCode = IC_RETURN_VALUE;
ins->mNumOperands = 1;
}
}
}
}
else

View File

@ -8651,6 +8651,9 @@ Expression* Parser::ParseFunction(Declaration * dec)
}
}
if (dec->mBase->mType == DT_TYPE_AUTO)
dec->mBase->mType = DT_TYPE_VOID;
mScope->End(mScanner->mLocation);
mScope = oscope;