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

Regression in operators handling #10052

Closed
RealyUniqueName opened this issue Jan 7, 2021 · 1 comment
Closed

Regression in operators handling #10052

RealyUniqueName opened this issue Jan 7, 2021 · 1 comment

Comments

@RealyUniqueName
Copy link
Member

Found by @ibilon: https://gist.github.com/ibilon/414b820c6bffe36139385d9dced3f929

@:forward(x, y)
abstract Point({x:Float, y:Float}) {
	public inline function new(x:Float, y:Float) {
		this = {x: x, y: y};
	}

	@:op(A + B) inline function add(other:Point):Point {
		return new Point(this.x + other.x, this.y + other.y);
	}

	@:op(A += B) inline function set_add(other:Point):Void {
		this.x += other.x;
		this.y += other.y;
	}
}

class Player {
	public final position = new Point(0, 0);
	public function new() {}
}

class Main {
	static function main() {
		final player = new Player();
		player.position += new Point(1, 1);
	}
}
Compiler failure
Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new
Attach the following information:
Haxe: 4.2.0-rc.1; OS type: unix;
File "src/typing/operators.ml", line 646, characters 57-64
Called from file "src/typing/operators.ml", line 646, characters 9-65
Called from file "src/typing/operators.ml", line 687, characters 7-60
Called from file "src/typing/typer.ml", line 753, characters 27-94
Called from file "src/typing/typer.ml", line 756, characters 9-19
Called from file "src/typing/typer.ml", line 1685, characters 10-38
Called from file "src/typing/typeloadFunction.ml", line 78, characters 2-25

Caused by #9751

@ibilon
Copy link
Member

ibilon commented Jan 7, 2021

Switching the order of the operator functions or making Player.position as var instead of final fix the issue.
So my guess is that the + operator is selected without seeing the final preventing it from working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants