www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9506] New: When using alias this, writeln modifies its argument

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506

           Summary: When using alias this, writeln modifies its argument
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: olli.pottonen paivola.fi


--- Comment #0 from Olli Pottonen <olli.pottonen paivola.fi> 2013-02-13
05:39:19 PST ---
The function writeln is not expected to modify its arguments, just print them.
However when a class uses alias this, writeln clears the member variable in
question.

Example:

import std.stdio;

class test {
   uint[] _p;
   alias _p this;

   this() { _p = [1, 2]; }
}

void main()
{
    test t = new test();
    writeln(t);
    writeln(t);
}

The expected output is
[1, 2]
[1, 2]
but instead the program outputs
[1, 2]
[]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-14
01:50:07 PST ---
This must be some kind of codegen bug, I can't recreate this on win32. I doubt
any code in writeln (or rather format) tries to do modifications like that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506



--- Comment #2 from Olli Pottonen <olli.pottonen paivola.fi> 2013-02-14
02:10:05 PST ---
(In reply to comment #1)
 This must be some kind of codegen bug, I can't recreate this on win32. I doubt
 any code in writeln (or rather format) tries to do modifications like that.

I suppose you're right about codegen. This bug is in v2.060 on OS X. I just tried v2.061, it works correctly. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com


--- Comment #3 from yebblies <yebblies gmail.com> 2013-06-30 13:41:13 EST ---
This should be closed if it can no longer be reproduced.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-06-30
05:30:39 PDT ---
I've tested this across several compiler versions on win32:

2.058: can't compile due to template instance error
2.059: broken: [1, 2] [ ]
2.060: broken: [1, 2] [ ]
2.061: ok:     [1, 2] [1 2]
2.062: ok:     [1, 2] [1 2]
2.063: broken: [1, 2] [ ]

Even if it was fixed at some point it looks like no test-cases were added, the
bug is back.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506



--- Comment #5 from yebblies <yebblies gmail.com> 2013-06-30 22:40:45 EST ---
Gah, we missed our window.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru
          Component|DMD                         |Phobos
         OS/Version|Mac OS X                    |All


--- Comment #6 from Maxim Fomin <maxim maxim-fomin.ru> 2013-06-30 07:19:06 PDT
---
Can reproduce on linux. I haven't found any codegen bug, but value
modification.

Old value = 2 //length of array
New value = 1
0x000000000043a3e6 in std.array.__T8popFrontTkZ.popFront() (a=0x7ffff7ed8ff0)
    at /usr/include/d/dmd/phobos/std/array.d:451
451        a = a[1 .. $];
(gdb) bt
#0  0x000000000043a3e6 in std.array.__T8popFrontTkZ.popFront() (
    a=0x7ffff7ed8ff0) at /usr/include/d/dmd/phobos/std/array.d:451
#1  0x000000000043af8c in
std.format.__T11formatRangeTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatRange()
(f=<error reading variable>, 
    val=0x7fffffffd808, w=0x7fffffffd820)
    at /usr/include/d/dmd/phobos/std/format.d:2155
#2  0x000000000043a312 in
std.format.__T11formatValueTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatValue()
(f=<error reading variable>, 
    val=0x7ffff7ed8fe0, w=...) at /usr/include/d/dmd/phobos/std/format.d:2572
#3  0x000000000043a256 in
std.format.__T13formatGenericTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatGeneric()
(f=<error reading variable>, 
    arg=0x7fffffffda60, w=...) at /usr/include/d/dmd/phobos/std/format.d:2996
#4  0x000000000043a13a in
std.format.__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTC4main4testZ.formattedWrite()
(_param_2=0x7ffff7ed8fe0, 
    fmt=..., w=...) at /usr/include/d/dmd/phobos/std/format.d:506
#5  0x0000000000439c58 in std.stdio.File.__T5writeTC4main4testTaZ.write() (
    this=0x695f80 <std.stdio.stdout()>, _param_1=10 '\n', 
    _param_0=0x7ffff7ed8fe0) at /usr/include/d/dmd/phobos/std/stdio.d:744
#6  0x0000000000439baa in std.stdio.__T7writelnTC4main4testZ.writeln() (
    _param_0=0x7ffff7ed8fe0) at /usr/include/d/dmd/phobos/std/stdio.d:1746
#7  0x0000000000437c3d in D main () at main.d:24 //file was modified

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013