HaxeFoundation / HaxeFoundation/haxe

static assign-ops overloads should be forbidden?

Open
#8,445 0 comments 0 reactions 0 assignees View on GitHub
feature-abstracts
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

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

```haxe
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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.