digitalmars.D.bugs - [Issue 6741] New: implicit casting of pure-function delegate result to immutable breaks immutability.
- d-bugmail puremagic.com (39/39) Sep 29 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6741
http://d.puremagic.com/issues/show_bug.cgi?id=6741 Summary: implicit casting of pure-function delegate result to immutable breaks immutability. Product: D Version: D2 Platform: Other OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: schveiguy yahoo.com --- Comment #0 from Steven Schveighoffer <schveiguy yahoo.com> 2011-09-29 10:46:04 PDT --- For example: class A { int n; void delegate( ) dg; void foo() {n++;} } pure A createAnA( int n ) { A result = new A; result.n = n; result.dg = &result.foo; return result; } void main( ) { immutable A tmp = createAnA( 3 ); assert( tmp.n == 3 ); tmp.dg(); assert( tmp.n == 4 ); } Because delegates cannot be cast, I think it should be illegal to cast a delegate-containing object or struct to immutable implicitly. An explicit cast should be required. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 29 2011