Bug 1649 – Variant coercion fails with delegates

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-11-08T10:47:00Z
Last change time
2015-06-09T01:14:22Z
Keywords
diagnostic
Assigned to
andrei
Creator
dhasenan

Attachments

IDFilenameSummaryContent-TypeSize
205variant.patchpatch to add a static asserttext/plain309

Comments

Comment #0 by dhasenan — 2007-11-08T10:47:48Z
--- 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).
Comment #1 by dhasenan — 2007-11-08T11:13:09Z
Created attachment 205 patch to add a static assert
Comment #2 by andrei — 2007-11-25T01:28:19Z
The fix will be committed in version 2.008. Thank you!
Comment #3 by braddr — 2007-11-25T03:28:57Z
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.
Comment #4 by dhasenan — 2007-11-25T07:45:18Z
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.
Comment #5 by bugzilla — 2008-12-25T04:40:59Z
Fixed dmd 2.022