Thread overview
[Issue 1211] New: mixin("__LINE__")
May 03, 2007
d-bugmail
May 03, 2007
d-bugmail
May 03, 2007
BCS
[Issue 1211] mixin("__LINE__") gives incorrect value
May 05, 2007
d-bugmail
May 05, 2007
BCS
May 06, 2007
Stewart Gordon
May 05, 2007
d-bugmail
May 05, 2007
d-bugmail
Jul 01, 2007
d-bugmail
May 03, 2007
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)


-- 

May 03, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1211


rueschi@giquadrat.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3
           Platform|Other                       |PC




-- 

May 03, 2007
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>


May 05, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1211


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Keywords|                            |wrong-code
            Summary|mixin("__LINE__")           |mixin("__LINE__") gives
                   |                            |incorrect value




------- Comment #2 from smjg@iname.com  2007-05-05 08:27 -------
> 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.


-- 

May 05, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1211





------- Comment #3 from davidl@126.com  2007-05-05 09:03 -------
how about
char[] a() {return `__LINE`;}
char[] b() {return `__`;}
mixin(a+b)


-- 

May 05, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1211





------- Comment #4 from smjg@iname.com  2007-05-05 09:54 -------
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.


-- 

May 05, 2007
d-bugmail@puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1211
> 
> 
> smjg@iname.com changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |smjg@iname.com
>            Keywords|                            |wrong-code
>             Summary|mixin("__LINE__")           |mixin("__LINE__") gives
>                    |                            |incorrect value
> 
> 
> 
> 
> ------- Comment #2 from smjg@iname.com  2007-05-05 08:27 -------
> 
>>writef("%\n", mixin(string)); // 1, 3 or 4? what about generated strings?
> 
> 
> What is %\n? 

a typeo

> And how is 3 a plausible value in your example?

1 is the line of the mixin
3 is the line in the string
4 is the file line where __LINE__ is
> 
> 
>>how about a dotted form?
>>
>><mixin_line>.<line_in_mixin>
> 
> 
> Then how would we distinguish between 2.1 and 2.10?
> 

__LINE__.typeof == int, != char[]  // Oops!!

May 06, 2007
"BCS" <BCS@pathlink.com> wrote in message news:f1j0hj$t6t$1@digitalmars.com...
>> And how is 3 a plausible value in your example?
>
> 1 is the line of the mixin
> 3 is the line in the string
> 4 is the file line where __LINE__ is
<snip>

No it isn't.  It's in line 4 of the string, and line 5 of the file.

Stewart. 

July 01, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1211


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #5 from bugzilla@digitalmars.com  2007-07-01 14:00 -------
Fixed DMD 1.018 and DMD 2.002


--