HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.14k stars 656 forks source link

haxe.PosInfos and macro #11712

Open filt3rek opened 2 months ago

filt3rek commented 2 months ago

Hej,

When using ?pos : haxe.PosInfos as last argument onto a macro function (inline expression) I get this message : haxe.PosInfos is not allowed on macro functions, use Context.currentPos() instead But It still works when using init macro functions, Idk if it's normal (I use it to get the call {methodName: toString, fileName: --macro Macro.test(), className: , lineNumber: 1} because haxe.macro.Context.currentPos() gives #pos((unknown)) and it would be handy if it gave us the build file position or something like that... And I get compiler error when doing that on build macro functions : https://try.haxe.org/#4C2d8a8e

Regards,

0b1kn00b commented 2 months ago

currentPos produces a Position which is opaque to the macro execution environment and can cause havoc if you try and construct one.

Position is part of the AST and separate and distinct from haxe.PosInfos which is only available in a runtime environment.

The try.haxe link is showing

Macro.hx:4: #pos(Test.hx:2: characters 1-8)
filt3rek commented 2 months ago

Sorry, I've given wrong url to try haxe for error, this is the correct one : https://try.haxe.org/#DeBb38Fb :

Compiler failure
Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new
Attach the following information:
Haxe: 4.3.4; OS type: unix;
File "src/typing/macroContext.ml", line 778, characters 18-25
Called from file "src/typing/macroContext.ml", line 778, characters 11-25
Called from file "list.ml", line 131, characters 32-39
Called from file "src/typing/macroContext.ml", line 772, characters 2-772
Called from file "src/typing/typeloadFields.ml", line 494, characters 16-45
Called from file "list.ml", line 110, characters 12-15
Called from file "src/typing/typeloadFields.ml", line 544, characters 1-44
Called from file "src/typing/typeloadFields.ml", line 742, characters 1-362
Called from file "src/typing/typeloadFields.ml", line 1740, characters 14-46
Called from file "src/typing/typeloadModule.ml", line 423, characters 5-70
Called from file "src/typing/typeloadModule.ml", line 454, characters 40-54
Called from file "src/context/typecore.ml", line 407, characters 3-6
Called from file "src/typing/finalization.ml", line 83, characters 1-30
Called from file "src/compiler/compiler.ml", line 278, characters 1-269
Called from file "src/compiler/compiler.ml", line 328, characters 3-24
Called from file "src/compiler/compiler.ml", line 354, characters 1-5
Called from file "src/compiler/compiler.ml", line 441, characters 2-157
Called from file "src/compiler/compiler.ml", line 415, characters 2-9
Called from file "src/compiler/compiler.ml", line 637, characters 5-43
Called from file "src/compiler/compiler.ml", line 647, characters 13-22
Called from file "src/compiler/server.ml", line 979, characters 1-39
[ERROR] (unknown position)

   | File "src/core/globals.ml", line 156, characters 1-7: Assertion failed

And ok, but I throwed this issue just to maybe uniform the behaviour because i.e. for init macro, haxe.PosInfos is kind of working giving me {methodName: toString, fileName: --macro Macro.test(), className: , lineNumber: 1} so it's not only working for runtime whereas haxe.macro.Context.currentPos() gives #pos((unknown)) in init macro...