Thread overview
[Issue 16662] Can't call std.variant.visit from a pure function
Jun 04, 2017
Paul Backus
Mar 20, 2018
Paul Backus
Dec 17, 2022
Iain Buclaw
December 15, 2016
https://issues.dlang.org/show_bug.cgi?id=16662

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com
           Assignee|nobody@puremagic.com        |alexandru.razvan.c@gmail.co
                   |                            |m

--
January 04, 2017
https://issues.dlang.org/show_bug.cgi?id=16662

Andrei Alexandrescu <andrei@erdani.com> changed:

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

--
June 04, 2017
https://issues.dlang.org/show_bug.cgi?id=16662

--- Comment #1 from Paul Backus <snarwin+bugzilla@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

--
December 16, 2017
https://issues.dlang.org/show_bug.cgi?id=16662

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ilyayaroshenko@gmail.com
           Severity|minor                       |normal

--
December 16, 2017
https://issues.dlang.org/show_bug.cgi?id=16662

--- Comment #2 from Илья Ярошенко <ilyayaroshenko@gmail.com> ---
Variant's "get" method is not pure too. It was a big surprise. No I need to figure out how to deal with it, the whole big project is pure.

--
March 20, 2018
https://issues.dlang.org/show_bug.cgi?id=16662

--- Comment #3 from Paul Backus <snarwin+bugzilla@gmail.com> ---
I've made some progress on this, but am unable to make VariantN.peek pure, because this if statement

    if (type != typeid(T))
        return null;

...calls object.opEquals, which is not pure. So issue #13933 needs to be fixed before we can solve this.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=16662

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--