__FILE__ and __LINE__ in case of import expression
Andrey Zherikov
andrey.zherikov at gmail.com
Sun Aug 23 12:42:25 UTC 2020
On Saturday, 22 August 2020 at 03:43:10 UTC, Steven Schveighoffer
wrote:
> On 8/21/20 6:34 PM, Adam D. Ruppe wrote:
>> On Friday, 21 August 2020 at 22:12:48 UTC, Steven
>> Schveighoffer wrote:
>>> And honestly, if it says the source is "mixin-50, line 1", I
>>> think people will get it.
>>
>> I could probably live with that too, but the status quo is
>> pretty useful as-is.
>
> I wonder if the compiler could detect when you are using a
> string literal vs. a generated or imported string, and change
> the behavior accordingly.
As far as I understand behavior of this is that mixin() changes
__FILE__ to point to the location of this mixin. But import
expression doesn't do so. So if import("file") could change
__FILE__ to "file" and __LINE__ to 1 internally that will make
sense IMHO.
I mean something like this:
//__FILE__='test', __LINE__=1
mixin( //__FILE__='test-mixin-2', __LINE__=2
//__FILE__='test-mixin-2', __LINE__=3
import("file") //__FILE__='file', __LINE__=1 - only
inside import() !!!
//__FILE__='test-mixin-2', __LINE__=5
)
//__FILE__='test', __LINE__=7
More information about the Digitalmars-d-learn
mailing list