Open Iluvatar opened 2 years ago
Indeed, that's a corner case that I didn't realize occurred when they added the current array index. I think I'll add a warning, though I've pretty much stopped working on overpy until I see what they're doing with the workshop in ow2. Thanks for reporting :)
When using list comprehensions that are both mapping and filtering, the generated code first does one then the other, leading to inconsistencies.
Example:
You'd expect
T
to be[2, 3]
. However, it compiles toSet Global Variable(T, Mapped Array(Filtered Array(Global.A, Compare(Current Array Element, ==, 4)), Current Array Index));
which first filters, then maps, leading to
[2, 2, 4, 4] => [4, 4] => T = [0, 1]
.It seems the workshop doesn't allow mapping and filtering at the same time. A rather heavy handed solution might be to first map elements to
[elem, index]
, then filter, then map back out. Or just include a warning or something.