www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1649] New: Variant coercion fails with delegates

reply d-bugmail puremagic.com writes:
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).


-- 
Nov 08 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1649






Created an attachment (id=205)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=205&action=view)
patch to add a static assert


-- 
Nov 08 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1649


andrei metalanguage.com changed:

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





The fix will be committed in version 2.008. Thank you!


-- 
Nov 24 2007
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1649


andrei metalanguage.com changed:

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




-- 
Nov 24 2007
parent reply Brad Roberts <braddr puremagic.com> writes:
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.
Nov 25 2007
parent Christopher Wright <dhasenan gmail.com> writes:
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.
Nov 25 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1649


bugzilla digitalmars.com changed:

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





Fixed dmd 2.022


-- 
Dec 25 2008