HaxeFoundation / HaxeFoundation/haxe

Error positions in 'fake' files are lost when using message.reporting=pretty

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

Description

This code:
Main.hx
```haxe
@:build(Macros.buildMain())
class Main {
}
```
Macros.hx
```haxe
import haxe.macro.Context;
class Macros {
public static function buildMain() {
var fields = Context.getBuildFields();
var fBody = "var a = 0;";
var pos = Context.makePosition({
file: 'myFile',
min: 0,
max: 27,
});
var expr = Context.parseInlineString(fBody, pos);
fields.push({
name: "erroredFunction",
kind: FFun({
args: [],
expr: expr,
}),
pos: pos,
});
return fields;
}
}
```
When compiled with `-D message.reporting=indent` yields
```
myFile:1: characters 10-11 : Unexpected ;
C:\Projects\shiroTools\haxe\std/haxe/macro/Context.hx:395: characters 10-46 : Called from here
Macros.hx:11: characters 20-57 : Called from here
Main.hx:2: characters 1-8 : Called from here
```
But when compiled with `-D message.reporting=pretty` yields
```
ERROR myFile

| Unexpected ;

-> C:\Projects\shiroTools\haxe\std/haxe/macro/Context.hx:395: characters 10-46

395 | return load("do_parse", 3)(expr, pos, true);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Called from here

-> Macros.hx:12: characters 20-57

12 | var expr = Context.parseInlineString(fBody, pos);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Called from here

-> Main.hx:1: characters 1-8

1 | @:build(Macros.buildMain())
| ^^^^^^^
| Called from here
```

**The error position `myFile:1: characters 10-11` is lost when using pretty message reporting**
If `pos` had a "real" file instead like Main.hx or Macros.hx it would show a position there, but that would make little sense in context.

My use case here is scripts contained in a large cdb file, for which we want relative positions, and the fake pos file looks like `'data.cdb/$sheetname/$id'`

Contributor guide

Open the contributing guide

Research direction

Reproduce the difference between message.reporting=indent and message.reporting=pretty using Main.hx and Macros.hx, with the position created by Context.makePosition. Read Context.hx around line 395 and trace the pretty reporter's handling of the fake file position. Done means pretty reporting preserves and displays myFile:1: characters 10-11 while retaining the existing call-site context.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.