HaxeFoundation / HaxeFoundation/haxe

Meta for methods that do not need a body

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

Description

Right now there are two cases where a body can be omitted:
1) For extern non-inline methods that represent functions present outside of haxe output.
2) For abstract operator forwarding.

But there is another group of methods that do not need a body present - those which just do not really need one for generators to produce them. I'm talking about those with `@:functionCode` (cpp, java, cs) and `@:hlNative` (hl).

They do not need one, but right now haxe requires it, so authors put something like return of a constant (usually null) or an empty block (if typed as void). Which feels/looks hacky (around the limitation), is not actual fallback that is expected to run on other targets (in most cases) and goes against null-safety when null is used as a fake return.

Extern modifier cannot be used here because extern methods are removed from a class before they reach a generator.

So, how about some meta that will say to the compiler that a body is not involved in a target generation?

If such meta is met without a body, a default fallback one will be automatically set with something like `throw new haxe.Exception("not implemented")` (which should satisfy any type of a method: void, non-void, abstract constructor).

Thoughts?

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.