HaxeFoundation / HaxeFoundation/haxe

@:posInfos to pass haxe.PosInfos to Reflect.makeVarArgs()

Open
#6,696 2 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

I think one of the most common use-cases for `Reflect.makeVarArgs()` would be for logging tools, and in the same breath one of the most common use-cases for `haxe.PosInfos` would be the usage in debug tools and loggers as well, since we can read out the line numbers of the call.

However those 2 don't work well together, although you would expect that that's how `trace()` works under the hood :
- It can take any number of arguments
- The last argument is `PosInfos`

Now currently if you want to replicate that behaviour, the only way is to redefine `trace()`. But in html5, you might not want to do that, since you don't want to just log out to `console.log` - you want to log out to `console.warn`, `console.error`, `console.debug`, `console.info` etc. - and of course you want to attach the line number of the call to it.

So assuming there's no other way to have a function with an arbitrary amount of arguments + `haxe.PosInfos` attached to it ( as it is in `trace` ), I would propose to add a `@:posInfos` metadata, that passes on `haxe.PosInfos` as the last parameter to a function when it's called.

This would also make the usage of `trace()` more standard and understandable, and would help with alternative logger solutions without them all having to redefine `trace` and possibly colliding with each other.

If I've missed anything and there is actually another alternative solution please feel free to play around with this example : https://try.haxe.org/#361D7

Contributor guide

Open the contributing guide

Research direction

Start with the linked try.haxe.org example and inspect the current behavior of Reflect.makeVarArgs() and trace(). Determine whether a metadata-based way to pass haxe.PosInfos is viable, and define completion as supporting arbitrary arguments with PosInfos attached for alternative logger functions.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.