HaxeFoundation / HaxeFoundation/haxe

[analyzer] returning (const) variable prevents optimization

Open
#7,934 6 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
feature-analyzer
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

```hx
class Test {
static function main() trace(test());
static function test() {
var ret = E.A;
if(ret == E.A) {
return ret;
} else return null;
}
}

enum E { A; B; }
```
Produces:
```js
Test.test = function() {
var ret = E.A;
if(ret == E.A) {
return ret;
} else {
return null;
}
};
```
But changing the `test` body to:
```hx
var ret = E.A;
if(ret == E.A) {
return E.A;
} else return null;
```
Will optimize it down to:
```js
Test.test = function() {
return E.A;
};
```

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.