Change strategy for the checking of function input types.

Rather than assert that the types are correct, use the force type functions on the parameters:
ff, fk, fs, q2f, v2f, and the new fi, fl.

These functions have also been modified to ensure that the input type supports an implicit typecast to the target type and perform it, or emit ELSLInvalidType otherwise, rather than an assertion failure. fl in particular returns the original list if it isn't changed, or a copy if it is.

A couple bugs were found in testfuncs.py as a result, which have been fixed as well. A test has been added to ensure that the exception that caught these bugs remains in place.

The isxxxx functions are no longer necessary, so they are removed. Same goes for the painful cast handling process in foldconst, which was basically performing this task, and not necessarily well.

This approach is much more robust and should have been used since the beginning, but I didn't figure it out then.
This commit is contained in:
Sei Lisa 2017-10-12 16:14:48 +02:00
parent 41d2c68cf8
commit 9e7a5d1cdf
5 changed files with 218 additions and 226 deletions

View file

@ -1115,32 +1115,7 @@ class foldconst(object):
# Call it
fn = sym['Fn']
args = [arg['value'] for arg in child]
argtypes = sym['ParamTypes']
assert(len(args) == len(argtypes))
for argnum in range(len(args)):
# Adapt types of params
if argtypes[argnum] == 'string':
args[argnum] = lslfuncs.fs(args[argnum])
elif argtypes[argnum] == 'key':
args[argnum] = lslfuncs.fk(args[argnum])
elif argtypes[argnum] == 'float':
args[argnum] = lslfuncs.ff(args[argnum])
elif argtypes[argnum] == 'vector':
args[argnum] = lslfuncs.v2f(args[argnum])
elif argtypes[argnum] == 'quaternion':
args[argnum] = lslfuncs.q2f(args[argnum])
elif argtypes[argnum] == 'list':
# ensure vectors and quaternions passed to
# functions have only float components
assert type(args[argnum]) == list
# make a shallow copy
args[argnum] = args[argnum][:]
for i in range(len(args[argnum])):
if type(args[argnum][i]) == Quaternion:
args[argnum][i] = lslfuncs.q2f(args[argnum][i])
elif type(args[argnum][i]) == Vector:
args[argnum][i] = lslfuncs.v2f(args[argnum][i])
del argtypes
assert len(args) == len(sym['ParamTypes'])
try:
# May raise ELSLCantCompute
if name[:10] == 'llDetected':