HaxeFoundation / HaxeFoundation/haxe

invalid position generated for single-expr blocks

Open
#6,742 0 comments 0 reactions 1 assignee Claimed by @Simn View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Single-expression blocks have the position of their only expression instead of their original expression:

```haxe
class Main {
static function main() {
some();
}

static function some() throw "impure";

#if macro
static function f() {
haxe.macro.Context.onGenerate(function(types) {
for (t in types) {
switch t {
case TInst(_.get() => cl, _) if (cl.name == "Main"):
function loop(e:haxe.macro.Type.TypedExpr) {
trace(e.expr.getName(), e.pos);
haxe.macro.TypedExprTools.iter(e, loop);
}
loop(cl.statics.get()[0].expr());
case _:
}
}
});
}
#end
}
```

```
haxe --macro "Main.f()" Main
```

```
Main.hx:15: TFunction,#pos(Main.hx:2: lines 2-4)
Main.hx:15: TBlock,#pos(Main.hx:3: characters 3-9)
Main.hx:15: TCall,#pos(Main.hx:3: characters 3-9)
Main.hx:15: TField,#pos(Main.hx:3: characters 3-7)
Main.hx:15: TTypeExpr,#pos(Main.hx:3: characters 3-7)
```

As you can see, TBlock's position is the same as TCall's, not its original one. This only happens when it's a single-expression block.

It's a bit of an issue for source mapping so would be nice to get fixed.

It happens somewhere in filters, because in a `onAfterTyping` callback it shows the correct position. My guess is that it happens when CFG building, the block is lost and then re-introduced, or something like that.

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.