__FILE__ and __LINE__ in case of import expression
Andrey Zherikov
andrey.zherikov at gmail.com
Fri Aug 21 14:01:24 UTC 2020
How can I get __FILE__ and __LINE__ values correct in case of
import expression?
Below is my test code.
/////////////////////////////////////////
test.d:
module test;
import std.stdio;
void test(string file = __FILE__, size_t line = __LINE__,
string mod = __MODULE__, string func = __FUNCTION__,
string pretty = __PRETTY_FUNCTION__,
string fileFullPath = __FILE_FULL_PATH__)
{
writefln("file: '%s', line: '%s', module: '%s',\nfunction:
'%s', " ~
"pretty function: '%s',\nfile full path: '%s'",
file, line, mod, func, pretty, fileFullPath);
}
int main(string[] args)
{
test(); // line #16 (1)
mixin(import("foo.d")); // line #17 (2)
return 0;
}
/////////////////////////////////////////
foo.d:
// empty line 1
// empty line 2
// empty line 3
// empty line 4
// empty line 5
test(); // line 6
/////////////////////////////////////////
Execution result is:
>dmd -J. -run test.d
file: 'test.d', line: '16', module: 'test',
function: 'test.main', pretty function: 'int test.main(string[]
args)',
file full path: 'C:\Users\andrey\test.d'
file: 'test.d-mixin-17', line: '22', module: 'test',
function: 'test.main', pretty function: 'int test.main(string[]
args)',
file full path: 'C:\Users\andrey\test.d-mixin-17'
So the output from line #16 (1) is correct although from line #17
(2) is not: file name is neither 'test.d' not 'foo.d' and line
number is 22 although both test.d and foo.d are shorter.
I understand that I can create a workaround but want to check
first whether this is desired behavior or a bug that should be
fixed?
More information about the Digitalmars-d-learn
mailing list