[Issue 16662] Can't call std.variant.visit from a pure function

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jun 4 15:28:07 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=16662

--- Comment #1 from Paul Backus <snarwin+bugzilla at gmail.com> ---
Seems like the culprit is VariantN.peek, which calls the property function
"type", which calls (through "fptr") an instance of the internal template
function "handler", which isn't pure.

Almost all of VariantN's operations use "handler" internally, so making it pure
would likely be difficult. On the other hand, modifying "fptr" to point to
different instances of "handler" is how VariantN keeps track of the type of the
stored object, so avoiding the use of "handler" would require substantial
changes to VariantN's implementation.

Here's the trail of breadcrumbs:

---

// test.d
import std.variant;

alias Example = Algebraic!(int, double);

void main() {
    Example x;
    pragma(msg, typeof(&x.peek!int));
    pragma(msg, typeof(&x.type));
}

---

$ dmd test.d
inout(int)* delegate() inout @property @system
TypeInfo delegate() const nothrow @property @trusted

$ dmd --version
DMD64 D Compiler v2.074.0

--


More information about the Digitalmars-d-bugs mailing list