HaxeFoundation / HaxeFoundation/haxe

[dce] Enum is not eliminated if placed in a separate module and referenced through a getter

Open
#9,107 0 comments 0 reactions 1 assignee Claimed by @RealyUniqueName View on GitHub
bug feature-dce
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Main.hx
```haxe
import TestClass;

class Main {
static function main() {
}
}
```
TestClass.hx
```haxe
class TestClass {
public var stdio(get,never):Array;
function get_stdio():Array return null;
}
```
TestEnum.hx
```haxe
enum TestEnum {}
```
Generated js:
```js
// Generated by Haxe 4.1.0-rc.1
(function ($global) { "use strict";
var $_;
function $extend(from, fields) {
// <...>
}
var Main = function() { };
Main.__name__ = true;
Main.main = function() {
};
Math.__name__ = true;
var TestEnum = $hxEnums["TestEnum"] = { __ename__ : true, __constructs__ : [] // <--- here
};
// <...>
```
As you can see `TestEnum` is not used, but still kept.
That happens for any target, but on js it also causes an exception on startup:
```
bin/test.js:15
var TestEnum = $hxEnums["TestEnum"] = { __ename__ : true, __constructs__ : []
^
ReferenceError: $hxEnums is not defined
at /home/alex/temp/test/bin/test.js:15:16
at Object. (/home/alex/temp/test/bin/test.js:100:3)
<...>
```
Changing `stdio` getter from `get` to `default` fixes it.
This is reproducible with 4.0.5 and the latest dev.

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.