https://d.puremagic.com/issues/show_bug.cgi?id=6741
--- Comment #2 from Steven Schveighoffer <schvei...@yahoo.com> 2014-03-20 12:57:35 PDT --- It's a bug because when the object is cast implicitly to immutable, it does not affect the context pointer. In essence, the delegate captures the instance when it was mutable. Normally, implicitly casting a pure return to immutable is OK because immutable is transitive. Since a strong pure function cannot have side effects, the return must be the only reference to it. However, if it contains a reference to itself via a delegate, that reference does NOT get cast to immutable. Why do you think the given code is correct behavior? I should never be able to do this without casts: immutable a = ... assert(a.n == 3); ... assert(a.n == 4); BTW, I do not say that a class with delegate members should not be allowed to be immutable, I'm saying that it should not *implicitly* cast to immutable. In other words, the code would be allowed if you did: auto tmp = cast(immutable(A))createAnA(3); In this case, you are telling the compiler "I know what I'm doing." -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------