haxe icon indicating copy to clipboard operation
haxe copied to clipboard

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

Open Speedphoenix opened this issue 6 months ago • 0 comments

This code: Main.hx

@:build(Macros.buildMain())
class Main {
}

Macros.hx

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'

Speedphoenix avatar May 14 '25 13:05 Speedphoenix