Null-conditional operators don't work properly with +=
|
|
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.
|