HaxeFoundation / haxe

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

[interp]interp cannot detect type mismatch at runtime #11440

Open sys9kdr opened 6 months ago

sys9kdr commented 6 months ago

problem

At runtime, --interp missing type mismatch. In python target , it can be detected at compile time. Expected that interp cause runtime error, but interp ignore error.

code

Test.hx:

// entrypoint
import JsonLoadMacro.listData;

final main = () -> {
    trace(listData());
}

JsonLoadMacro.hx:

macro function listData():ExprOf<Array<Int>> {
    final path = './data.json';
    final json = haxe.Json.parse(sys.io.File.getContent(path));
    return macro $v{json};
}

interp.hxml:

-main Test
--interp

py.hxml

-main Test
-python test.py

how to reproduce

$ git clone https://github.com/sys9kdr/haxe-interp-miss-err # or paste above codes into project root
$ haxe py.hxml # err; expected!
$ haxe interp.hxml # no err but actually types are mismatch!
kLabz commented 6 months ago

This is enough:

function main() trace([1,2,"wat"]);
sys9kdr commented 6 months ago

The problem is that type errors do not thrown in interp, but in python.

My concern is the differences between platforms, not the usability of trace.

Simn commented 6 months ago

This is really about trace and its special typing in order to make hello-world programs on JS (and apparently python) look nicer. You won't like the fix here because it's going to make the error disappear on those targets as well. It's the expected behavior when typing against Dynamic, which is the argument type of haxe.Log.trace.

sys9kdr commented 6 months ago

ahh sorry, I finally understand. I updated my repo with simpler ones. https://github.com/sys9kdr/haxe-interp-miss-err/tree/trace-differences-between-targets

I checked interp and lua allow mixed array, but python and js don't. Is this deference a problem or design?