HaxeFoundation / HaxeFoundation/haxe

Generated python code initializes static variables in the wrong order

Open
#10,562 8 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

**Environment**
macos monterey 12.1
haxe 4.2.4
utest 1.13.2
haxe-concurrent 3.0.2

The issue can be reproduced by creating a test case like the following one (even if the issue is triggered by the interaction between the libraries `utest` and `haxe-concurrent`, I don’t think that it is caused by them as I’m explaining below)

```
package foo;

import utest.Assert;

class TestCase extends utest.Test {
static var ex = hx.concurrent.executor.Executor.create();

function testFoo() {
Assert.pass();
}
}
```

The reported error is

```
Traceback (most recent call last):
File "/Users/foo/temp/bin/python/main.py", line 6819, in
foo_TestCase.ex = hx_concurrent_executor_Executor.create()
File "/Users/foo/temp/bin/python/main.py", line 745, in create
return hx_concurrent_executor_ThreadPoolExecutor(maxConcurrent,autostart)
File "/Users/foo/temp/bin/python/main.py", line 819, in __init__
super().__init__()
File "/Users/foo/temp/bin/python/main.py", line 730, in __init__
super().__init__()
File "/Users/foo/temp/bin/python/main.py", line 622, in __init__
haxe_Log.trace((("[" + Std.string(self)) + "] instantiated."),_hx_AnonObject({'fileName': "hx/concurrent/Service.hx", 'lineNumber': 57, 'className': "hx.concurrent.ServiceBase", 'methodName': "new"}))
File "/Users/foo/temp/bin/python/main.py", line 1978, in trace
python_Lib.printString((("" + ("null" if str1 is None else str1)) + HxOverrides.stringOrNull(python_Lib.lineEnd)))
AttributeError: type object 'python_Lib' has no attribute 'lineEnd'
Error: Command failed with error 1
```

The last part of the generated python file is this

```
foo_TestCase.ex = hx_concurrent_executor_Executor.create()
hx_concurrent_ConcurrentException.INDENT = " "
hx_concurrent_executor_ScheduleTools.HOUR_IN_MS = 3600000
hx_concurrent_executor_ScheduleTools.DAY_IN_MS = 86400000
hx_concurrent_executor_ScheduleTools.WEEK_IN_MS = 604800000
hx_concurrent_lock_RLock.isSupported = True
python_Lib.lineEnd = ("\r\n" if ((Sys.systemName() == "Windows")) else "\n")
utest_TestHandler.POLLING_TIME = 10
utest_AccessoryName.SETUP_NAME = "setup"
utest_AccessoryName.SETUP_CLASS_NAME = "setupClass"
utest_AccessoryName.TEARDOWN_NAME = "teardown"
utest_AccessoryName.TEARDOWN_CLASS_NAME = "teardownClass"

foo_TestAll.main()
sys_thread__Thread_Thread_Impl_.processEvents()
```

As you can see the problem is that the executor `hx_concurrent_executor_Executor`, which internally uses `python_Lib.lineEnd` for logging, is created before the variable `lineEnd` is assigned.

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.