immutable singleton pattern with static opCall
Justin Johansson
no at spam.com
Sat Jun 26 17:28:01 PDT 2010
Michal Minich wrote:
> On Sun, 27 Jun 2010 09:36:04 +0930, Justin Johansson wrote:
>
>> immutable class Foo
>> {
>> static private Foo instance;
>>
>> static this() { // line 9
>> instance = new Foo;
>> }
>>
>> static Foo opCall() { // line 13
>> return instance;
>> }
>> }
>>
>> test.d(9): Error: function test.Foo._staticCtor2 without 'this' cannot
>> be const/immutable
>> test.d(13): Error: function test.Foo.opCall without 'this' cannot be
>> const/immutable
>
> there is bug report on this subject
>
> http://d.puremagic.com/issues/show_bug.cgi?id=3598
>
> Your example also uses static variable, which was not considered in the
> bug report. This makes things more complex to design properly, because it
> seems now that one does not want static functions to be affected by
> immutable attribute of class, but it should affect static data...
Thanks for your quick response and analysis.
I agree that "it should affect static data". Since this bug impedes
the use of good functional style, imho this is a *serious* bug.
More information about the Digitalmars-d
mailing list