Silently typecast integer value to float.
The build was successful. Details

This is a necessary step, to allow passing integer numbers. Otherwise, every float variable would need a floating point value. In other words, "float $x = 5" is allowed construct. Without this simple change, only accepted
construction was "float $x = 5.0".
This commit is contained in:
Rafal Kupiec 2018-09-16 20:02:34 +02:00
parent 58103ea5fe
commit 82998ffd0f
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 16 additions and 6 deletions

View File

@ -4983,10 +4983,14 @@ static sxi32 VmByteCodeExec(
} }
} }
} else if(aFormalArg[n].nType != MEMOBJ_MIXED && ((pArg->iFlags & aFormalArg[n].nType) == 0)) { } else if(aFormalArg[n].nType != MEMOBJ_MIXED && ((pArg->iFlags & aFormalArg[n].nType) == 0)) {
ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType); if(aFormalArg[n].nType == MEMOBJ_REAL && (pArg->iFlags & MEMOBJ_INT)) {
xCast(pArg); /* Silently typecast integer value to float */
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType);
"Argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName); xCast(pArg);
} else {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName);
}
} }
} }
if(aFormalArg[n].iFlags & VM_FUNC_ARG_BY_REF) { if(aFormalArg[n].iFlags & VM_FUNC_ARG_BY_REF) {
@ -5070,8 +5074,14 @@ static sxi32 VmByteCodeExec(
goto Abort; goto Abort;
} }
if(aFormalArg[n].nType != MEMOBJ_MIXED && aFormalArg[n].nType > 0 && ((pObj->iFlags & aFormalArg[n].nType) == 0)) { if(aFormalArg[n].nType != MEMOBJ_MIXED && aFormalArg[n].nType > 0 && ((pObj->iFlags & aFormalArg[n].nType) == 0)) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, if(aFormalArg[n].nType == MEMOBJ_REAL && (pObj->iFlags & MEMOBJ_INT)) {
"Default value for argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName); /* Silently typecast integer value to float */
ProcMemObjCast xCast = PH7_MemObjCastMethod(aFormalArg[n].nType);
xCast(pObj);
} else {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Default value for argument %u of '%z()' does not match the data type", n + 1, &pVmFunc->sName);
}
} }
/* Insert argument index */ /* Insert argument index */
sArg.nIdx = pObj->nIdx; sArg.nIdx = pObj->nIdx;