ID:2569765
 
Resolved
The null-conditional operator could cause the proc stack to grow if it caught a null and was used in a right-hand-side expression, e.g. calling a?.b() without assigning the result to a var.
BYOND Version:513.1522
Operating System:Windows 10 Home
Web Browser:Firefox 75.0
Applies to:Dream Daemon
Status: Resolved (514.1550)

This issue has been resolved.
Descriptive Problem Summary:

It seems that if x?.y is used 65 535 times with x = null runtime errors appear. Those seem to be not directly related to the x?.y expression (almost as if other vars got corrupted). Specifically in the snippet below it's usually either "runtime error: type mismatch: cannot compare to 65535" or "runtime error: type mismatch: cannot compare /list (/list) to 65535" or even dream seeker straight up crashing. Note that it doesn't happen if the number is lowered to 65534, if z isn't null or if we access a variable instead of a proc.

Actually I lied, it happens for variables too but only if I do:
var/mob/z = null
for(var/i = 1; i <= 65535; i++)
z?.name

and not for e.g.
var/mob/z = null
for(var/i = 1; i <= 65535; i++)
z?.name = "what"

or
var/mob/z = null
for(var/i = 1; i <= 65535; i++)
if(z?.name) world.log << "what"


Also it seems to happen if this is done across multiple variables, not just z in the examples above / below.

Numbered Steps to Reproduce Problem:
1.) Run the snippet below (optionally replace mob and Bump with other types and procs).
2.) Stare in awe at the runtime error

Code Snippet (if applicable) to Reproduce Problem:
var/mob/z = null
for(var/i = 1; i <= 65535; i++)
z?.Bump()


Expected Results:
The code runs successfuly without calling Bump on anything.

Actual Results:
Runtime error or Dream Daemon crash.

Does the problem occur:
Every time? Or how often? Always.
In other games? N/A
In other user accounts? Probably.
On other computers? Yes.

When does the problem NOT occur?
When the number is less than 65 535.
When we access a variable using ?. and assign to it.
When we access a variable using ?. and use the value.
When the object ?. is called upon isn't null.

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.)
I haven't tested extensively but 513.1517 suffers from the problem too and I assume it probably existed for a long time.

Workarounds:
Use isnull(z) ? null : z.Bump() instead.
This might mean the stack is filling when it shouldn't. I'll look into it.
still occurs in 514, btw
Hrm, looks like this might have gotten buried.
Lummox JR resolved issue with message:
The null-conditional operator could cause the proc stack to grow if it caught a null and was used in a right-hand-side expression, e.g. calling a?.b() without assigning the result to a var.