Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading assignment and compound assignment operators is silently ignored #6903

Closed
matrefeytontias opened this issue Mar 13, 2018 · 4 comments

Comments

@matrefeytontias
Copy link

matrefeytontias commented Mar 13, 2018

https://try.haxe.org/#D769b

class Entity
{
    public var x:Float;
    public var y:Float;
    public var theta:Float;
    
    public function new()
    {
        x = 1.;
        y = 2.;
        theta = 3.;
    }
}

typedef Position = { x:Float, y:Float };

@:forward
abstract Bleh(Position) from Position
{
    public function new()
    {
        this = {x:0., y:0.};
    }
    
    @:op(a = b) public function setTo(a:Bleh) : Bleh
    {
        trace("Bleh");
        this.x = a.x;
        this.y = a.y;
        return this;
    }
}

class Test
{
    static function main()
    {
        var a:Bleh = { x:1., y:1. };
        var b = new Entity();
        var c:Bleh = b;
        c.x = 3.;
        c.y = 3.;
        c = a;
        trace(b.x, b.y);
    }
}
@matrefeytontias matrefeytontias changed the title Overloads of assignment and compound assignment operators are silently ignored Overloading assignment and compound assignment operators is silently ignored Mar 13, 2018
@RealyUniqueName
Copy link
Member

duplicates #5738

@back2dos
Copy link
Member

Well, not quite. This issue could quite easily be resolved by issuing an error message that = cannot be overloaded. The other one is less trivial.

@matrefeytontias
Copy link
Author

I'd rather have it allow overloading the different assignments operators really. I didn't know about the other issue, but I guess that while I do agree with what has been said in it, this one can become a different one (the fail shouldn't be silent).

@Justinfront
Copy link
Contributor

Justinfront commented Mar 14, 2018

@matrefeytontias I believe also the 'precedence of operators' is also predefined so if you where to try abstracting around a float and swap + and * around it would not work as you might expect, because * would still have precedence.

@Simn Simn added this to the Bugs milestone Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants