Thread overview | |||||
---|---|---|---|---|---|
|
September 06, 2010 [Issue 4832] New: Functions external to class break immutability | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=4832 Summary: Functions external to class break immutability Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-09-06 13:37:14 PDT --- Code: import std.stdio : writeln; void foo(ref int x) { x = 10; } class Bar { immutable int x; this() { x = 5; } void printMe() { writeln(this.x); } void change() { //~ this.x = 20; // illegal, errors out } } void main() { Bar bar = new Bar; bar.printMe(); // prints 5 //~ bar.x = 10; // illegal, errors out foo(bar.x); // no error! bar.printMe(); // prints 10 } The commented out code would error out at compile time, which is expected. But the function bar() is breaking immutability of x. A relevant bug is bug 4416 , and my comment: http://d.puremagic.com/issues/show_bug.cgi?id=4416#c1 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 06, 2010 [Issue 4832] Functions external to class break immutability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=4832 --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-09-06 13:37:55 PDT --- Sorry, I meant the function foo, not bar. (In reply to comment #0) > Code: > > import std.stdio : writeln; > > void foo(ref int x) > { > x = 10; > } > > class Bar > { > immutable int x; > > this() > { > x = 5; > } > > void printMe() > { > writeln(this.x); > } > > void change() > { > //~ this.x = 20; // illegal, errors out > } > } > > void main() > { > Bar bar = new Bar; > bar.printMe(); // prints 5 > > //~ bar.x = 10; // illegal, errors out > > foo(bar.x); // no error! > bar.printMe(); // prints 10 > } > > The commented out code would error out at compile time, which is expected. But the function bar() is breaking immutability of x. > > A relevant bug is bug 4416 , and my comment: http://d.puremagic.com/issues/show_bug.cgi?id=4416#c1 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 27, 2011 [Issue 4832] Functions external to class break immutability | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=4832 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |yebblies@gmail.com Resolution| |DUPLICATE --- Comment #2 from yebblies <yebblies@gmail.com> 2011-01-26 18:27:09 PST --- *** This issue has been marked as a duplicate of issue 5493 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation