`Sys.programPath()` running the interp?

My goal is to get the directory in which the executable is located. For other sys targets I was using Path.directory(Sys.programPath()) but looks like Sys.programPath() doesn’t work in interp and fails with a not very informative error:


function main()

$ haxe --run Main

Results in
[0] Instance prototype not found: haxe.macro.Error

Is it expected behavior? I understand that in interp scenario it’s not entirely clear what the “program path” should be but is there a good solution for my task?

My current idea is to run the program in a bash script and passing the scripts path through an environment variable. Like this:


export EXEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
haxe --run Main

and then use Sys.getEnv('EXEDIR') instead of Path.directory(Sys.programPath()).
It works but this solution feels a bit weird…

I’m using Haxe 4.2.5 on Mac (Apple M1)

That kind of error should not happen here, please open an issue.

Done: `Sys.programPath()` fails on Interp target: `[0] Instance prototype not found: haxe.macro.Error` · Issue #11169 · HaxeFoundation/haxe · GitHub