ID:2658334
 
BYOND Version:513
Operating System:Windows XP Pro x64
Web Browser:Chrome 88.0.4324.190
Applies to:Dream Daemon
Status: Open

Issue hasn't been assigned a status value.
Descriptive Problem Summary:

This is two conflated issues that Lummox helped with on the BYOND Discord. I couldn't fit both issues into the title. Apologies if any of this is unclear, my understanding is limited and this bug report is more for a reference for Lummox.

1. The values returned by block() will include instances that have not finished being created properly if the block() range includes turfs that have been created by increasing the map size, but have not yet finished being created. Specifically, this issue appeared alongside DMMSuite resizing the dimensions of the map, followed by a created turf iterating over its neighbors in New().

2. When iterating on the result of block() in a typed loop:
for(var/turf/T in block(foo))

the usual implicit istype check on T for /turf is skipped because (quoting Lummox): "The compiler is adding an "as turf" clause to the loop because you defined T as a turf, and that kicks in some internal optimizations so when it's looping through a list it skips any item that doesn't have the internal MAP_REF data type."

Numbered Steps to Reproduce Problem:
I am not completely sure how to reproduce this outside of the SS13 case, so I will paste the discussion with Lummox:

[3:51 PM] Lummox JR: Okay, I see what's happening.
[3:53 PM] Lummox JR: ResizeWorldMap() is being called during DMMsuite to load the new map. When new turfs get filled in, they're given the default area and then assigned a type path, then New() is called. This happens in a loop (which I could stand to optimize).
[3:54 PM] Lummox JR: So, the problem here is that New() is being called on a turf that's been fully created, but that turf's New() is doing stuff to check its neighbors that have not been created.
[3:54 PM] Lummox JR: That is, they have indexes and valid refs, but no valid type path yet.
[3:56 PM] Lummox JR: This suggests to me I might need to make some changes to map resizes to avoid this situation as well. I don't like that it's possible for turfs with null types to be encountered.

Code Snippet (if applicable) to Reproduce Problem:
Can't provide one sorry!

Expected Results:
block() should probably only return turf instances that have finished being created, and typed loops should possibly not optimize quite so aggressively with simple types? Unsure on the latter.

Actual Results:
block() can return turf instances that don't pass istype(), but also skip istype() in typed loops due to the loop being optimized by the compiler.

Does the problem occur:
Every time? Or how often? Every time.
In other games? Haven't tested but Lummox indicated the typed loop behavior is compiler related.
In other user accounts? See above.
On other computers? See above.

When does the problem NOT occur?
When you explicitly typecheck the returned value from block(), ie.
for(var/thing in block(foo))
var/turf/T = thing
if(istype(T))
...


Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
Did not test on any earlier version.

Workarounds:
Explicitly typecheck the result of block() as above.