digitalmars.D.bugs - [Issue 9166] New: std.typecons.Nullable doesn't work with a not mutable type
- d-bugmail puremagic.com (49/49) Dec 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9166
- d-bugmail puremagic.com (6/6) Dec 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9166
- d-bugmail puremagic.com (19/19) Dec 26 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9166
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 --- Comment #0 from bearophile_hugs 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: -------
Dec 16 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9166 --- Comment #1 from bearophile_hugs eml.cc 2012-12-16 18:47:03 PST --- See also Issue 9164 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 16 2012
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 --- Comment #2 from bearophile_hugs eml.cc 2012-12-26 15:58:54 PST --- 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