[Issue 9404] Nullable is unusable with 2.061
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jan 26 13:21:57 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9404
monarchdodra at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |monarchdodra at gmail.com
--- Comment #2 from monarchdodra at gmail.com 2013-01-26 13:21:56 PST ---
Here is a preliminary analysis:
There is no opAssign(Nullable!T t).
Because of this doing a "nullable1 = nullable2" will actually trigger
"nullable1 = nullable2.get", at which point an exception is thrown. In the
second example:
b = a; //This fails regardless of DMD
This can be fixed with:
//----
void opAssign()(Nullable!T other)
{
_value = other._value;
_isNull = other._isNull;
}
//----
That said I wonder if this is correct behavior: if "a" is null, then should "b
= a" work? I think so, but I can see reasons why it shouldn't.
----------------
The real question is: Why did the first example ever work at all? I've tracked
it down to this usecase, with *at least*, a 3-level nest:
//----
import std.typecons;
import std.stdio;
struct S
{
void opAssign(int){writeln("opAssign");}
int get(){writeln("get"); return 1;}
alias get this;
}
struct SS
{
S s;
}
struct SSS
{
SS ss;
this(SS i)
{
ss = i;
}
}
void main() {
SS ss;
SSS(ss);
}
//----
DMD 2.060:
//----
//----
DMD 2.061:
//----
get
opAssign
//----
AFAIK, 2.061 is the correct behavior. Something must have been fixed in 2.061,
so that explains the *change* in behavior. So there should be nothing to fix
there... But I'll let own of the compiler guys confirm.
In any case, I'll fix open a pull to improve Nullable to accept assignment from
another nullable.
--
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