[Issue 6741] New: implicit casting of pure-function delegate result to immutable breaks immutability.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Sep 29 10:46:41 PDT 2011
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 at puremagic.com
ReportedBy: schveiguy at yahoo.com
--- Comment #0 from Steven Schveighoffer <schveiguy at 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: -------
More information about the Digitalmars-d-bugs
mailing list