ID:2630871
 
Resolved
The ?. operator on the left-hand side of an assignment operator worked incorrectly in certain cases when adding/assigning some constant values such as negative numbers.
BYOND Version:513
Operating System:Windows 10 Pro 64-bit
Web Browser:Chrome 86.0.4240.111
Applies to:Dream Maker
Status: Resolved (513.1537)

This issue has been resolved.
Descriptive Problem Summary:
Version: 513.1536
When code following a certain pattern involving the `?.` and `+=` operators with a negative literal value is compiled, the resulting executable actually tries to add `null` to the left-hand-side instead of the correct number.

It happens with "-=" as well (and potentially others.)

Numbered Steps to Reproduce Problem:
1) Run the snippet

Code Snippet (if applicable) to Reproduce Problem:
/datum
var/info

/world/New()
// Shows the bug not decrementing the number
world.log << "FIRST TEST"
var/datum/x = new
x.info = 1337
world.log << "Value before: [x.info]"
x?.info += -1
world.log << "Value after: [x.info]"

// Shows the bug placing `null` into an empty list.
world.log << "\nSECOND TEST"
var/datum/y = new
y.info = list()
world.log << "Length before: [length(y.info)]"
y?.info += -1
world.log << "Length after: [length(y.info)]"
world.log << "First entry == null: [y.info[1] == null]"


Expected Results:
First block of code: The `x.info` field should become `1336`
Second block of code: The list at `y.info` should have `-1` appended to it.

Actual Results:
First block of code: The `x.info` field does not change.
Second block of code: The list at `y.info` has `null` appended to it.

Does the problem occur:
It occurs every time as long as the code follows the pattern `x?.y += -literal`

When does the problem NOT occur?
Switching `?.` for `.`, or making sure the literal is positive stops the problem from happening.

Lummox JR resolved issue with message:
The ?. operator on the left-hand side of an assignment operator worked incorrectly in certain cases when adding/assigning some constant values such as negative numbers.