www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9166] New: std.typecons.Nullable doesn't work with a not mutable type

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9166

           Summary: std.typecons.Nullable doesn't work with a not mutable
                    type
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



import std.typecons: Nullable;
void main() {
    auto n = Nullable!(immutable int)(5);
}


DMD 2.061alpha gives:

...\dmd2\src\phobos\std\typecons.d(1170): Error: can only initialize const
member _value inside constructor
test.d(3): Error: template instance std.typecons.Nullable!(immutable(int))
error instantiating




The problem is in this part of std.typecons.Nullable:


/**
Assigns $(D value) to the internally-held state. If the assignment
succeeds, $(D this) becomes non-null.
 */
    void opAssign()(T value)
    {
        _value = value;
        _isNull = false;
    }



If I put it inside a "static if" it seems to work:


    static if (isMutable!T) {
        /**
        Assigns $(D value) to the internally-held state. If the assignment
        succeeds, $(D this) becomes non-null.
         */
            void opAssign()(T value)
            {
                _value = value;
                _isNull = false;
            }
    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 16 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9166




See also Issue 9164

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 16 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9166


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|std.typecons.Nullable       |std.typecons.Nullable and
                   |doesn't work with a not     |NullableRef don't work with
                   |mutable type                |a not mutable type



The same happens with NullableRef:


import std.typecons: NullableRef;
alias NII = NullableRef!(immutable int);
void main() {}



...\dmd2\src\phobos\std\typecons.d(1451): Error: cannot modify immutable
expression *this._value
test.d(2): Error: template instance std.typecons.NullableRef!(immutable(int))
error instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 26 2012