digitalmars.D.bugs - [Issue 17645] New: `pure` is transitively applied to all delegates
- via Digitalmars-d-bugs (29/29) Jul 13 2017 https://issues.dlang.org/show_bug.cgi?id=17645
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 puremagic.com Reporter: tomer 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 --
Jul 13 2017