Test case at the bottom.
When using the input type `anything` in a for loop while iterating over special lists such as contents, it fails to iterate at all. One workaround produces a warning, and the other one works, but it'd still be nice for `anything` to work as I would expect it to.
Using these flavors of constructions is useful in the case where you don't want to istype the contents of the list every iteration. Furthermore, with this specific input type construction, you save a GET & SETVAR.
The for loop construction looks like this:
/turf/floor/Entered(atom/movable/Obj,atom/OldLoc)
for (var/atom/movable/type/x as anything in src)
x.foo()
However, this does not work, and will fail to iterate over any contents of the turf.
You can do a similar 'typeless' loop to get similar behavior (no istype check), but it involves setting a local var which adds additional instructions:
/turf/floor/Entered(atom/movable/Obj,atom/OldLoc)
for (var/O in src)
var/atom/movable/type/x = O
x.foo()
By saving the GET & SETVAR instructions, a multiple tests showed that the for-loop w/ input type construction was ~50% faster than a typed loop, and ~33% faster than the above typeless loop. This can make a big difference in games like SS13, where you can iterate over many millions of things throughout a round.
Expected Results:
To iterate properly over special lists. It's possible, as detailed in 'Workarounds' below.
Actual Results:
Failing to iterate properly.
Does the problem occur:
Every time? Or how often? every time
In other games? yes
On other computers? yes
Workarounds:
Curiously, the input types `as color` and `as command_text` evaluate to a different loop instruction (ITERLOAD) which is useful for us. This results in the bitflag in the instruction being set to `0` instead of `4096` for "anything".
These let us use this construction, and they also work with special lists, but it produces a warning which isn't acceptable.
You can replace the `as anything` with `as color` in the test case if you want to see this behavior in action.
As I was writing this post, we found a really nice workaround:
/turf/floor/Entered(atom/movable/Obj,atom/OldLoc)
for (var/atom/movable/type/x as() in src)
x.foo()
This does work as expected for our purposes, but does read strangely. It'd still be nice if `anything` could work for special lists.
Relevant old post: http://www.byond.com/forum/post/157258#comment662447
Test Case:
https://drive.google.com/file/d/ 19i9ho_kmfM12cpx3X2uoKfuEpCEnk7SV
OR
https://cdn.discordapp.com/attachments/517361638504923136/ 762020006069403658/typecheckless.zip
OR
http://www.mediafire.com/file/atcxyy7kmnwa5ap/ typecheckless.zip/file
OR
https://gofile.io/d/NdEF2s