HaxeFoundation / HaxeFoundation/haxe

Uninitialized Final Field Ignored When Using Macro in Haxe Compiler

Open
#12,023 4 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

### Description

When defining a final variable in an interface, implementing it in an abstract class, and inheriting that abstract class in another class, we are expected to initialize the final variable either in the abstract class or the derived class. Otherwise, the compiler correctly throws an error:

`Some final fields are uninitialized in this class`

However, when using a macro that adds a new variable to the abstract class and invoking it via `@:autoBuild(Macro.build())`, the compiler fails to enforce initialization for the final variable defined in the interface. This results in an uninitialized final variable being accepted, which contradicts expected behavior.

### Steps to Reproduce

[Reproduction Example in Haxe Sandbox](https://try.haxe.org/#2c96c07F)

### Expected Behavior

The compiler should enforce initialization of the final variable defined in the interface, regardless of the applied macro.

### Actual Behavior

When the macro is applied, the compiler does not report an error for an uninitialized final variable.

### Environment

Haxe Compiler Version: `4.3.6`
Target Platform: JavaScript (others are not tested)

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.