Error with builtin reduce function used in a function in deferred mode
The following example causes an error in deferred evaluation mode:
min(s) = reduce((x, y: if(x<y, x, y)), s)
a = (n: 2., 3.)
print(reduce((x, y: if(x<y, x, y)), a)) # this always works
print(min(a)) # this causes the error
The error is:
Traceback (most recent call last):
File "vre-language/src/virtmat/language/utilities/errors.py", line 97, in wrapper
return func(*args, **kwargs)
File "vre-language/examples/../scripts/run_model.py", line 89, in evaluate_prog
print(f'program output: >>>\n{prog.value}\n<<<')
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/utilities/errors.py", line 36, in wrapper
return func(*args, **kwargs)
File "vre-language/src/virtmat/language/interpreter/instant_executor.py", line 50, in program_value
vals = [p.value for p in get_children_of_type('Print', self) if p.value]
File "vre-language/src/virtmat/language/interpreter/instant_executor.py", line 50, in <listcomp>
vals = [p.value for p in get_children_of_type('Print', self) if p.value]
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/utilities/errors.py", line 43, in wrapper
raise TextXError(str(err), **loc, context=con) from err
textx.exceptions.TextXError: vre-language/examples/2.vm:4:1: => 'print(min(a))'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "vre-language/examples/../scripts/run_model.py", line 127, in <module>
main()
File "vre-language/examples/../scripts/run_model.py", line 123, in main
evaluate_prog(clargs, prog)
File "vre-language/src/virtmat/language/utilities/errors.py", line 99, in wrapper
process_error(err)
File "vre-language/src/virtmat/language/utilities/errors.py", line 82, in process_error
raise err.__cause__
File "vre-language/src/virtmat/language/utilities/errors.py", line 36, in wrapper
return func(*args, **kwargs)
File "vre-language/src/virtmat/language/utilities/types.py", line 132, in wrapper
return checktype_(func(obj), obj.type_)
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 922, in func_value
func, pars = self.func
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 54, in print_func
func_pars = [par.func for par in self.params]
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 54, in <listcomp>
func_pars = [par.func for par in self.params]
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 70, in print_parameter_func
return self.param.func
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 718, in function_call_func
retfunc = self.expr.func
File "/usr/lib/python3.10/functools.py", line 981, in __get__
val = self.func(instance)
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 509, in reduce_func
mapping = [next(i for i, a in enumerate(npars_u) if a == p) for p in npars]
File "vre-language/src/virtmat/language/interpreter/deferred_executor.py", line 509, in <listcomp>
mapping = [next(i for i, a in enumerate(npars_u) if a == p) for p in npars]
StopIteration