Thread overview
[Issue 1649] New: Variant coercion fails with delegates
Nov 08, 2007
d-bugmail
Nov 08, 2007
d-bugmail
Nov 25, 2007
d-bugmail
Nov 25, 2007
d-bugmail
Nov 25, 2007
Brad Roberts
Nov 25, 2007
Christopher Wright
Dec 25, 2008
d-bugmail
November 08, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1649

           Summary: Variant coercion fails with delegates
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: dhasenan@gmail.com


---
auto v = Variant({ return false; });
v.coerce!(bool delegate());
---

This produces the output:
/home/gareis/prog/dmd/src/phobos/std/variant.d(565): function
std.variant.VariantN!(maxSize).VariantN.coerce!(bool delegate()).coerce
expected to return a value of type bool delegate()
/home/gareis/prog/dmd/src/phobos/std/variant.d(5): template instance
std.variant.VariantN!(maxSize).VariantN.coerce!(bool delegate()) error
instantiating

It should static assert false if the type you are trying to coerce to is not supported (struct, delegate, etc).


-- 

November 08, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1649





------- Comment #1 from dhasenan@gmail.com  2007-11-08 11:13 -------
Created an attachment (id=205)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=205&action=view)
patch to add a static assert


-- 

November 25, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1649


andrei@metalanguage.com changed:

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




------- Comment #2 from andrei@metalanguage.com  2007-11-25 01:28 -------
The fix will be committed in version 2.008. Thank you!


-- 

November 25, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1649


andrei@metalanguage.com changed:

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




-- 

November 25, 2007
http://www.dsource.org/projects/phobos/browser/candidate/phobos/std/variant.d?rev=511

Why static assert(false) rather than return false?  Additionally, if you're going to static assert(false), then a message ought to be included since it's going to result in a nice meaningless compilation failure.

Additionally.. add a code block -> add a unit test!

Lastly, stop doing trivial bug fixes on the candidate branch.  They belong directly on the trunk.
November 25, 2007
Brad Roberts wrote:
> http://www.dsource.org/projects/phobos/browser/candidate/phobos/std/variant.d?rev=511
> 
> Why static assert(false) rather than return false? 

Coerce doesn't allow that. Besides which, it's better to fail early -- if Variant doesn't support that operation, it shouldn't compile, since it'll ALWAYS fail at runtime. And if the user wants something like that, they'll just put assert(false) in their code.

> Additionally, if you're going to static assert(false), then a message ought to be included since it's going to result in a nice meaningless compilation failure.
> 
> Additionally.. add a code block -> add a unit test!

We can actually do that now, using __traits(compiles).

unittest {
   Variant v = 5;
   assert (!__traits(compiles, v.coerce!(bool delegate())));
}

> Lastly, stop doing trivial bug fixes on the candidate branch.  They belong directly on the trunk.
December 25, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1649


bugzilla@digitalmars.com changed:

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




------- Comment #5 from bugzilla@digitalmars.com  2008-12-25 04:40 -------
Fixed dmd 2.022


--