Browse Source

Silently typecast integer value to float.

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".
pull/50/head
Rafal Kupiec 3 years ago
parent
commit
82998ffd0f
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 16 additions and 6 deletions
  1. +16
    -6
      engine/vm.c

+ 16
- 6
engine/vm.c View File

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


Loading…
Cancel
Save