[Issue 17645] New: `pure` is transitively applied to all delegates inside a pure function
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Jul 13 05:03:21 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17645
Issue ID: 17645
Summary: `pure` is transitively applied to all delegates inside
a pure function
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: tomer at weka.io
DMD64 D Compiler v2.074.0. Consider the following:
static int x;
void f() pure {
auto dg = (){x++;};
}
src/dtest.d(45,19): Error: pure delegate 'dtest.f.__lambda1' cannot access
mutable static data 'x'
Had I invoked dg() inside f(), this error would be correct. But I'm only
creating a delegate, which I will pass to some external, non-pure entity, which
is allowed to call it.
The use-case here is that sometimes we need the compiler to "just trust us" and
assume something is pure. It's used in exception cases which would soon after
reach an abort() so we don't consider this impure. And this restriction is too
broad for us
--
More information about the Digitalmars-d-bugs
mailing list