__FILE__ and __LINE__ in case of import expression

Steven Schveighoffer schveiguy at gmail.com
Fri Aug 21 21:42:21 UTC 2020


On 8/21/20 5:08 PM, Adam D. Ruppe wrote:
> On Friday, 21 August 2020 at 21:06:11 UTC, Steven Schveighoffer wrote:
>> The hybrid line number (original source line number + mixin line 
>> number) seems like a bug to me.
> 
> I'm not so sure without seeing all the code. Remember to the compiler, 
> the mixin thing is just a big string literal at the location of the 
> import statement.
> 
> So it adds the number of \n's in the string literal to the original line 
> number to get the mixin line number.

Look at the OP. It says line 22. Neither test.d nor the imported foo.d 
has 22 lines.

While not necessarily a "bug", it's not very useful. The compiler should 
output a useful line number. I shouldn't have to do math to figure out 
what it "really" means.

I'd argue that should be the line number based on the mixin source. The 
file name already is based on the line the string was mixed in, so both 
items contain useful data.

To be fair to the compiler, when you are mixing in an import, the mixin 
doesn't know that the string came from an imported file, so it can't 
really determine the file automatically. But the line number should be 
reasonable.

-Steve


More information about the Digitalmars-d-learn mailing list