ID:2375652
 
Resolved
The null-conditional dot and colon operators didn't work correctly with operate-and-assign operators such as += and also the ++ and -- operators. The code for these operators has been completely redesigned to avoid this problem.

NOTE: Any projects that use the null-conditional operators, or 512's new dot/colon "chaining", need to be recompiled for the new version!

Also note: When a null-conditional is used as the left side of an assignment, the right-hand side will NOT be evaluated if the null check fails. This means that a?.b = c++ will not increment c if a is null; it is treated as equivalent to if(!isnull(a)) a.b = c++. This was never explicitly stated in the reference but has been documented going forward.
BYOND Version:512
Operating System:Windows 10 Home
Web Browser:Chrome 66.0.3359.181
Applies to:Dream Daemon
Status: Resolved (512.1428)

This issue has been resolved.
Descriptive Problem Summary:
Attempting to use += (and presumably any of the other operators that both read and write, though I only tested +=) with the null-conditional operators results in a runtime if the owner of the variable is null.
Tested in 512.1414 and 512.1426. Presumably applies to all versions of 512.

Code Snippet (if applicable) to Reproduce Problem:
/obj/test
var/thing = 0

/proc/main()
var/obj/test/O
O?.thing += 1


Expected Results:
Absolutely nothing

Actual Results:
runtime error: Cannot read null.thing

Workarounds:
Do what you always would have prior to 512.
Good find. I'm gonna have to investigate all the cases this applies to and figure out a fix. I also realized there's some other incorrect code related to this that slipped through an earlier revision.
At last I've managed to get somewhere on this, which basically involved mostly undoing what I did in id:2311311 and handling these operators in a way that's a hybrid between the old way and something new. This also meant I had to add code to "roll" assignment and side-effect operators so they occur beneath the conditional dot. Kind of a pain, but it works now. Just finishing up final testing.
Lummox JR resolved issue with message:
The null-conditional dot and colon operators didn't work correctly with operate-and-assign operators such as += and also the ++ and -- operators. The code for these operators has been completely redesigned to avoid this problem.

NOTE: Any projects that use the null-conditional operators, or 512's new dot/colon "chaining", need to be recompiled for the new version!

Also note: When a null-conditional is used as the left side of an assignment, the right-hand side will NOT be evaluated if the null check fails. This means that a?.b = c++ will not increment c if a is null; it is treated as equivalent to if(!isnull(a)) a.b = c++. This was never explicitly stated in the reference but has been documented going forward.