HaxeFoundation / HaxeFoundation/haxe

[eval] `null` is passed to a macro instead of an expression of non-xml in specific circumstances

Open
#8,927 2 comments 0 reactions 0 assignees View on GitHub
platform-macro
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Main.hx
```haxe
import haxe.macro.Expr;

class Main {
static function main() {
jsx(main);
}

macro static function jsx(expr:Expr):Expr;
}
```
Main.macro.hx
```haxe
import haxe.macro.Expr;

class Main {
static function jsx(expr):Expr {
trace(expr);
return switch expr.expr {
case EMeta({name: ":markup"}, {expr: EConst(CString(s))}):
macro $v{"XML MARKUP: " + s};
case _:
throw new haxe.macro.Expr.Error("not an xml literal", expr.pos);
}
}
}
```
```
$ haxe -main Main -js bin/test.js
Main.macro.hx:5: null
Main.macro.hx:6: characters 19-23 : Uncaught exception field access on null
Main.hx:5: characters 3-13 : Called from here
Main.hx:3: lines 3-9 : Defined in this class
```
To "fix" it one needs to either add a type hint to `expr` argument of `jsx` function or move whole `jsx` function into `Main.hx`

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.