[Issue 23633] New: allow pure functions to call impure functions passed as parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 16 01:29:10 UTC 2023


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

          Issue ID: 23633
           Summary: allow pure functions to call impure functions passed
                    as parameters
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: destructionator at gmail.com

Basically, permit this:

```
void foo(void delegate() dg) pure {
        dg();
}
```

Similarly to how you can write to values passed through params, if an impure
delegate is passed through params I think we can allow that as an extension of
the weakly pure concept. This would allow things like passing properties to be
set.

If you are passed a class/interface tho, probably should only allow the pure
members since that's not as explicit as the delegates.

I often find myself wanting some kind of limited environment to a function, and
pure ALMOST offers it, but it just isn't able to do enough since pure is too
strict, this kid of relaxation just might make it work.

--


More information about the Digitalmars-d-bugs mailing list