[Issue 16662] New: Can't call std.variant.visit from a pure function
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Nov 4 20:07:05 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16662
Issue ID: 16662
Summary: Can't call std.variant.visit from a pure function
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
Under dmd 2.072, calling std.variant.visit from inside a pure function is
forbidden, even if all of the functions used to instantiate visit are
themselves pure.
Example code:
import std.variant;
alias IntOrString = Algebraic!(int, string);
IntOrString twice(IntOrString v) pure {
return v.visit!(
(int n) pure => IntOrString(2*n),
(string s) pure => IntOrString(s ~ s)
)();
}
...and the compiler error:
Error: pure function 'test2.twice' cannot call impure function
'std.variant.visit!(function (int n) => VariantN(& handler, cast(ubyte)0u,
).this(2 * n), function (string s) => VariantN(& handler, cast(ubyte)0u,
).this(s ~ s)).visit!(VariantN!(16LU, int, string)).visit'
--
More information about the Digitalmars-d-bugs
mailing list