[Issue 2074] Variant arithmetic operations fail
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 6 08:54:02 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2074
andrei at metalanguage.com changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|bugzilla at digitalmars.com |andrei at metalanguage.com
------- Comment #1 from andrei at metalanguage.com 2008-05-06 10:54 -------
(In reply to comment #0)
> The following program fails:
>
> -----------------------
>
> import std.stdio;
> import std.variant;
>
> Variant a;
> Variant b;
>
> void main ()
> {
> a=2;
> b=3;
> writeln(b-a);
> }
>
> -------------------------------
>
> With the error:
>
> testar.d(11): Error: overloads VariantN!(maxSize)(VariantN!(maxSize)
> rhs) and VariantN!(maxSize)(VariantN!(maxSize)
> lhs) both match argument list for opSub
Thanks for the reports! The problem is surprisingly subtle: opSub and opSub_r
are both templates, so both match for a-b. I fixed the bug by embarrassing
manual duplication and will commit to next release unless somebody comes with a
better solution.
In the meantime, you may want to replace in
your_dmd_installation/src/phobos/src/variant.d the function opSub_r with the
following hecatomb:
VariantN opSub_r(int lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(uint lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(long lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(ulong lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(float lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(double lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
VariantN opSub_r(real lhs)
{
return VariantN(lhs).opArithmetic!(VariantN, "-")(*this);
}
--
More information about the Digitalmars-d-bugs
mailing list