HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.17k stars 654 forks source link

`Sys.programPath()` fails on Interp target: `[0] Instance prototype not found: haxe.macro.Error` #11169

Open miriti opened 1 year ago

miriti commented 1 year ago

Haxe v4.2.5

Main.hx:

function main()
  trace(Sys.programPath());
haxe --run Main

Results in:

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

I'm getting the same result on both Mac (M1) and Linux (amd64).

Simn commented 1 year ago

This is quite funny, apparently it tries to report the Main class, but doesn't find one because there isn't one. The actual error is Module Main does not define type Main. So there are two problems here:

  1. It has to account for module-level main
  2. It should not fail while trying to locate haxe.macro.Error
miriti commented 1 year ago

Indeed. I've wrapped this code in a class and now it works!

class Main {
  public static function main()
    trace(Sys.programPath());
}