HaxeFoundation / HaxeFoundation/haxe
eval code leaked into source code via macros
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I'm running into an issue where eval-related identifiers seem to be inserted into the target output.
This isn't a critical issue, since the haxe code itself is invalid. However, the compiler doesn't complain and generates invalid target code instead, which can cause a bit of confusion to sort out.
E.g., given:
```haxe
import haxe.macro.Expr;
class Foo {
macro public static function macroFunc(enm : Expr) : Expr {
return macro function() {
return macro null;
};
}
}
```
and the following use case:
```haxe
class Main {
static function main(){
var foo = Foo.macroFunc(Page);
}
}
```
(with Lua target)
I get the following error:
```
lua: out.lua|399 info| unexpected symbol near '$'
```
The culprit is an identifier called `$__mk_pos__` that gets inserted into the output. That isn't generated in genlua, but I found a few places in `evalJit.ml` and `reification.ml` where it is referenced.
Here's the generated code showing the mk_pos call:
```lua
...
Main.main = function()
local foo = function()
do return _hx_o({__fields__={expr=true,pos=true},expr=__haxe_macro_ExprDef.EConst(__haxe_macro_Constant.CIdent("null")),pos=$__mk_pos__("Foo.hx", 159, 163)}) end;
end;
local param_parser = nil;
end
```
Contributor guide
Assessment
This issue has not been assessed yet.