Any way to get file/line for symbol declaration?

Andre Pany andre at s-e-a-p.de
Sun Jun 9 21:35:52 UTC 2019


On Sunday, 9 June 2019 at 21:26:52 UTC, Manu wrote:
> I have some reflection-heavy validation code, it's necessary 
> that I emit meaningful error messages to the user explaining 
> when inputs don't meet expectation.
>
> I'm finding that emitting an FQN along with the error messages 
> is not
> super productive.
> I'd REALLY like to emit the error with the proper file and line 
> prefix
> so that you can click and code editors will go to the problem
> declaration.
>
> I can't find any way to dig the Loc of the declaration from the 
> symbol reference. Does anyone know any tricks? Should I make a 
> PR to expose the symbol Loc as a traits?

I have a very similar use case. I need for a module name the 
filename. I also thought about s.th. like
__traits(file, "module name")
The idea is, the return value is the same like __FILE__ in the 
scope of the module.

Anything which would enable it would be very welcome.

Kind regards
Andre


More information about the Digitalmars-d mailing list