Skip to content

static assign-ops overloads should be forbidden? #8445

Description

@nadako

Something like this does not make much sense and it doesn't work, even if addAssign is inline, because a will be tempvared.

abstract A(Int) from Int {
	function asInt() return this;

	@:op(a += b) static function addAssign(a:Int, b:A):Int {
		return a += b.asInt();
	}
}

class Main {
	static function main() {
		var a = 10;
		var b:A = 5;
		a += b;
		trace(a); // still 10
	}
}

I think assign-ops only make sense when this can be asssigned to, that is, inline non-static methods. So should we error on this kind of @:op definitions?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions