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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 16 18:22:51 PST 2012


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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-12-16 18:22:44 PST ---
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: -------


More information about the Digitalmars-d-bugs mailing list