Weird behavior for right aligned rectangle

I have a rectangle with its origin set to its right upper corner:

let rect = scene.add.rectangle(10, 0, 10, 1).setOrigin(1, 0);

Then I change its width:

rect.width = 5;

This when things starting to get weird. I’ll try to demonstrate the problem drawing with 'x’s. This is my original rect:

xxxxxxxxxx

When I reduce its width to 5 I expected to get this:

     xxxxx

My rect’s origin is set to (1, 0), see above. I expected it to stay on its position of 10. But what I got is this:

xxxxx

But it gets better: when I ask the rect for its position, it claims to still be at a 10:

console.log(rect.x) -> yields 10

Clearly, that is not true:

xxxxx
         '
         10 is here

Now, I can imagine how the internal math always adds or subtracts on the right side of the rectangle yielding this weird behavior. But this could be easily solved by ensuring that the resulting rect would stay on its assigned position respecting its origin.

Is this a bug? Or is this the way it should be?

Use setSize(w, h) instead.