1211 – mixin("__LINE__") gives incorrect value

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1211 - mixin("__LINE__") gives incorrect value
Summary: mixin("__LINE__") gives incorrect value
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks:
Reported: 2007年05月03日 12:53 UTC by Rueschi
Modified: 2014年02月16日 15:22 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Rueschi 2007年05月03日 12:53:34 UTC
import std.stdio;
void main() { writefln("%d", mixin("__LINE__")); }
Expected output: 2
Actual output: 1 (everywhere)
Comment 1 Nazo Humei 2007年05月03日 14:10:22 UTC
Reply to d-bugmail@puremagic.com,
> http://d.puremagic.com/issues/show_bug.cgi?id=1211
> 
> Summary: mixin("__LINE__")
> Product: D
> Version: 1.010
> Platform: Other
> OS/Version: Windows
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla@digitalmars.com
> ReportedBy: rueschi@giquadrat.de
> import std.stdio;
> void main() { writefln("%d", mixin("__LINE__")); }
> Expected output: 2
> Actual output: 1 (everywhere)
Well what would you expect? There is more than one option.
writef("%\n", mixin(string)); // 1, 3 or 4? what about generated strings?
const char[] string = " 
__LINE__";
how about a dotted form?
<mixin_line>.<line_in_mixin>
Comment 2 Stewart Gordon 2007年05月05日 08:27:28 UTC
> writef("%\n", mixin(string)); // 1, 3 or 4? what about generated strings?
What is %\n? And how is 3 a plausible value in your example?
> how about a dotted form?
> 
> <mixin_line>.<line_in_mixin>
Then how would we distinguish between 2.1 and 2.10?
IMO it should be the line in which it's mixed in, as that's the first point at which __LINE__ is treated as a token rather than being in a string. If you want the line where __LINE__ actually is in the code, you'd have to use
 writef("%d\n", mixin(string)); // BTW what is %\n???
 const char[] string = " 
 " ~ __LINE__.stringof;
This leaves:
- the line within the mixed-in code - if we're going to have this, it should probably be by a different token such as __MIXIN_LINE__.
- the line at which it would appear in the code after expansion of the mixin - but I don't see any practical use for this.
Comment 3 david 2007年05月05日 09:03:03 UTC
how about 
char[] a() {return `__LINE`;}
char[] b() {return `__`;}
mixin(a+b)
Comment 4 Stewart Gordon 2007年05月05日 09:54:52 UTC
The + operator doesn't work on strings, so what's to ask?
If you meant a ~ b, then how I stated it should work works equally in this case.
Comment 5 Walter Bright 2007年07月01日 14:00:53 UTC
Fixed DMD 1.018 and DMD 2.002


AltStyle によって変換されたページ (->オリジナル) /