Page MenuHomeFeedback Tracker

Arrays as HashMap values cannot be deep copied
Closed, ResolvedPublic

Description

If you store an array in a HashMap value and return it as deep copy, it still gets modified in the HashMap

Details

Severity
None
Resolution
Not A Bug
Reproducibility
Always
Operating System
Windows 10 x64
Operating System Version
Newest
Category
Scripting
Steps To Reproduce
myHashmap = createHashmap;
myHashmap set ["test", []];

private _myArray = + (myHashmap get "test");
_myArray pushBack "test";
hint str myHashmap

returns

[["test", ["test"]]];

it should be

[["test", []]]

only if I do this, it would be right:

private _myArray = (myHashmap get "test");

Event Timeline

nflug created this task.Mar 3 2021, 9:27 AM
nflug edited Steps To Reproduce. (Show Details)
nflug edited Steps To Reproduce. (Show Details)
dedmen changed the task status from New to Need More Info.Mar 3 2021, 10:24 AM
dedmen added a subscriber: dedmen.
myHashmap = createHashmap; 
myHashmap set ["test", []]; 
 
private _myArray = + (myHashmap get "test"); 
_myArray pushBack "test";

myHashmap

No repro.

myHashmap = createHashmap; 
myHashmap set ["test", []]; 
 
private _myArrayRef = (myHashmap get "test"); 
private _myArray = + (myHashmap get "test"); 
_myArray pushBack "test";

_myArrayRef

No repro

myHashmap = createHashmap; 
myHashmap set ["test", []]; 
 
private _myArrayRef = (myHashmap get "test"); 
private _myArray =  (myHashmap get "test"); 
_myArray pushBack "test";

_myArrayRef

works as intended.

nflug added a comment.Mar 3 2021, 11:06 AM

Found out that the problem was that it was not in brackets

private _myArray = + myHashmap get "test";

now it works.

private _myArray = + (myHashmap get "test");

Of course, unary + has higher precedence than get, so it gets resolved first. https://community.bistudio.com/wiki/Operators#Order_of_Precedence

dedmen closed this task as Resolved.Mar 4 2021, 6:43 PM
dedmen claimed this task.
dedmen changed Resolution from Open to Not A Bug.