www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2074] New: Variant arithmetic operations fail

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

           Summary: Variant arithmetic operations fail
           Product: D
           Version: 2.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: arkangath gmail.com


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


-- 
May 06 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla digitalmars.com    |andrei metalanguage.com






 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); } --
May 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074






I think that there may be other operations failing, opDiv being one of them.
I'm unsure about opMod however.


-- 
May 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED






 I think that there may be other operations failing, opDiv being one of them.
 I'm unsure about opMod however.
Probably everything that has an opXyz_r, sigh. Andrei --
May 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074






I looked into it some more and I think the best engineering solution is to
remove support for right-hand-side operations in Variant.

This would require the occasional explicitness, e.g. Variant(5) - x instead of
5 - x, but I see that as a small disadvantage that avoids a hecatomb of
bloating in the source.

Please advise.


-- 
May 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074







 I looked into it some more and I think the best engineering solution is to
 remove support for right-hand-side operations in Variant.
 
 This would require the occasional explicitness, e.g. Variant(5) - x instead of
 5 - x, but I see that as a small disadvantage that avoids a hecatomb of
 bloating in the source.
 
 Please advise.
 
Truly, it would be best to sacrifice the right-hand-side operations. The rationale for this decision however should be stated on the documentation. Perhaps someday a compromise of D's operator overloading (or template instantiation) may be reached which makes these operations possible. --
May 06 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2074


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED





Fixed in 2.014.


-- 
May 17 2008