HaxeFoundation / HaxeFoundation/haxe

[suggestion] @:forward.op for abstracts

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

Description

https://try.haxe.org/#f89E633f
```hx
class Test {
static function main() {
var x = Example.a * 5;
trace(x);
}
}

enum abstract Example(Float) to Float {
var a = 0;
var b = 1;
}
```

The above results in:
> [ERROR] Test.hx:3: characters 11-20
> 3 | var x = Example.a * 5;
> | ^^^^^^^^^
> Example should be Int

something like this crops up often where the solution is to do `var x = (Example.a:Float) * 5;` or write the @:op's for the abstract

It would be nice if we could have a `@:forward.op` meta which in this particular situation would remove the need to have the `to Float` in a lot of cases

Contributor guide

Open the contributing guide

Research direction

Start by running the linked try.haxe.org example and confirming the abstract member access error. Investigate the compiler entry points for abstract forwarding and @:op metadata; done means defining the proposed @:forward.op behavior and making the example compile without explicit casts or repeated operators.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.