[ENG-3954] Treat ArrayVar.foreach index as int (#4193)

* [ENG-3954] Treat ArrayVar.foreach index as int

* foreach: convert return value to a Var

When the value returned from the foreach is not hashable (mutable type), then
it will raise an exception if it is not first converted to a LiteralVar.
This commit is contained in:
Masen Furer 2024-10-17 16:16:24 -07:00
parent 542382c3e7
commit a6b2e640ac
No known key found for this signature in database
GPG Key ID: B0008AD22B3B3A95

View File

@ -1155,7 +1155,7 @@ class ArrayVar(Var[ARRAY_VAR_TYPE]):
function_var = ArgsFunctionOperation.create(tuple(), return_value)
else:
# generic number var
number_var = Var("").to(NumberVar)
number_var = Var("").to(NumberVar, int)
first_arg_type = self[number_var]._var_type
@ -1167,7 +1167,10 @@ class ArrayVar(Var[ARRAY_VAR_TYPE]):
_var_type=first_arg_type,
).guess_type()
function_var = ArgsFunctionOperation.create((arg_name,), fn(first_arg))
function_var = ArgsFunctionOperation.create(
(arg_name,),
Var.create(fn(first_arg)),
)
return map_array_operation(self, function_var)