Control: Comparing equal mappings yields unexpected result

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
2 posts • Page 1 of 1
ChristianGoehring
Posts:14
Joined: Fri Feb 24, 2017 9:29 am

Control: Comparing equal mappings yields unexpected result

Post by ChristianGoehring »

I stumbled upon a unexpected behaviour in Control when comparing mapping objects. Consider the following code:

Code: Select all

  const mapping m1 = makeMapping("x", makeMapping("y", true), "a", "b");  
  const mapping m2 = makeMapping("x", makeMapping("y", true), "a", "b");
  
  DebugTN(m1 == m2);
This outputs "TRUE" on the log as expected. But the following code:

Code: Select all

  const mapping m1 = makeMapping("x", makeMapping("y", true), "a", "b");  
  mapping m2 = makeMapping("x", makeMapping("y", true));
  m2["a"] = "b";
  
  DebugTN(m1 == m2);
outputs "FALSE on the command line even though the mappings are the same in terms of keys and values. You can verify this via output on the log. If you compare with casting it to string before, it works:

Code: Select all

  const mapping m1 = makeMapping("x", makeMapping("y", true), "a", "b");  
  const mapping m2 = makeMapping("x", makeMapping("y", true), "a", "b");
  
  mapping m3 = makeMapping("x", makeMapping("y", true));
  m3["a"] = "b";
  
  DebugTN(m1, m2, m3);
  
  DebugTN("(m1 == m2)="+(m1 == m2));
  DebugTN("(m2 == m3)="+(m2 == m3));
  DebugTN("(m1 == m3)="+(m1 == m3));

  DebugTN("((string)m1 == (string)m2)="+((string)m1 == (string)m2));
  DebugTN("((string)m2 == (string)m3)="+((string)m2 == (string)m3));
  DebugTN("((string)m1 == (string)m3)="+((string)m1 == (string)m3));
This outputs on my machine (3.15 P010 Win7)
WCCOActrl4:2018.07.19 13:20:05.451[mapping 2 items
WCCOActrl4: "x" : mapping 1 items
WCCOActrl4: "y" : TRUE
WCCOActrl4: "a" : "b"
WCCOActrl4:][mapping 2 items
WCCOActrl4: "x" : mapping 1 items
WCCOActrl4: "y" : TRUE
WCCOActrl4: "a" : "b"
WCCOActrl4:][mapping 2 items
WCCOActrl4: "x" : mapping 1 items
WCCOActrl4: "y" : TRUE
WCCOActrl4: "a" : "b"
WCCOActrl4:]
WCCOActrl4:2018.07.19 13:20:05.451["(m1 == m2)=TRUE"]
WCCOActrl4:2018.07.19 13:20:05.451["(m2 == m3)=FALSE"]
WCCOActrl4:2018.07.19 13:20:05.451["(m1 == m3)=FALSE"]
WCCOActrl4:2018.07.19 13:20:05.451["((string)m1 == (string)m2)=TRUE"]
WCCOActrl4:2018.07.19 13:20:05.451["((string)m2 == (string)m3)=TRUE"]
WCCOActrl4:2018.07.19 13:20:05.451["((string)m1 == (string)m3)=TRUE"]
I am acutally expecting the comparison between the same mappings to be true - am I missing something? Maybe there is a mappingCmp method but I did not see anything like this ...

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: Control: Comparing equal mappings yields unexpected result

Post by mkoller »

The reason is: When you assign a value to a key which is not in the mapping yet, a new entry is being created before the assignment then puts the value at that key, but the new empty entry gets initially a "mixed" datatype,
which is different than what happens when you create a mapping directly via makeMapping().

2 posts • Page 1 of 1