openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

Curious order of operation mismatch (intuition vs implementation) #455

Closed XertroV closed 4 months ago

XertroV commented 5 months ago
void Test() {
  nat3 v1 = nat3(1, 2, 3);
  auto buf = MemoryBuffer(100);
  buf.Write(v1.x);
  buf.Write(v1.y);
  buf.Write(v1.z);
  buf.Seek(0);
  nat3 v2 = nat3(buf.ReadUInt32(), buf.ReadUInt32(), buf.ReadUInt32());
  if (v1.x != v2.x) throw("Mismatching!");
}

I would expect this to work correctly (i.e., v2 == v1)

However, I found that v2 == nat3(v1.z, v1.y, v1.x)

Reading the nat3 like this works:

    auto x = buf.ReadUInt32();
    auto y = buf.ReadUInt32();
    auto z = buf.ReadUInt32();
    v2 = nat3(x, y, z);

Is this even a bug? I would have thought arguments were evaluated in order, but doesn't seem like it.

Might be something to report to angelscript forums, but it'd also be a breaking change to fix it if anyone relied on this behavior for some reason.

codecat commented 4 months ago

This is not a bug, and is intended according to the Angelscript documentation:

If a function takes more than one argument, the argument expressions are evaluated in the reverse order, i.e. the last argument is evaluated first.