HaxeFoundation / HaxeFoundation/haxe

Module level private fields overrides other module's imported static fields of the same name

Open
#12,951 0 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

It's gonna take me a good while, to narrow down a solid simplified repro of this, but adding the following mod-level fields to a class to FlxSpriteExt.hx:
```hx
private final log = new Logger("SpriteExt");
private var assert(get, never):debug.Assert;
private inline function get_assert()
return log.assert;

private final logSound = log.sub("Sound");
```
And the following to ControlButton.hx:
```hx
private final log = new debug.Logger("ControlButton");
private var assert(get, never):debug.Assert;
inline private function get_assert() return log.assert;
```

Causes 45 completely unrelated files with similar module fields to throw compile errors like this:
> [ERROR] source/chompy/props/facilities/NestFacility.hx:305: characters 4-10
>
> 305 | assert(animName == anim);
> | ^^^^^^
> | Cannot access private field assert

Note this only happened on haxe 5 preview 1, haxe 4 didn't seem to mind. Also note that all of the erroring files in question imported the static fields (not module level) of a another class, like so:
```hx
import data.ChompG.log;
import data.ChompG.assert;
```

Or in fewer cases:
```hx
import debug.Logger.log;
import debug.Logger.assert;
```

I add these private module level fields on many, many files, I thought it was because FlxSpriteExt was added to an import.hx file, causing everything to import it, but that wasn't the case for ControlButton, and just fixing FlxSpriteExt.hx (by changing mod fields to statics) wasn't enough to fix it, alone I also had to fix ControlButtons.hx in the same manner.

I'll work on finding a solid repro in a bit

Contributor guide

Open the contributing guide

Research direction

Start with the module fields in FlxSpriteExt.hx and ControlButton.hx, then inspect the affected imports such as data.ChompG.log and data.ChompG.assert. Reduce the report to a solid reproduction and compare its behavior on Haxe 5 preview 1 and Haxe 4. Done means unrelated files can use imported static fields without private module fields causing access errors.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.