Calling dynamically bound functions from weakly pure function
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 22 08:19:52 PDT 2014
On Tuesday, 22 July 2014 at 13:35:27 UTC, Rene Zwanenburg wrote:
> On Saturday, 19 July 2014 at 11:12:00 UTC, Marc Schütz wrote:
>> Casting to pure would break purity if the called function is
>> not actually pure. AFAIU, the problem is that the mutable
>> function pointers are not accessible from inside the pure
>> function at all, in which case the solution is to cast them to
>> immutable, not to pure.
>
> Indeed that is the problem. I didn't think of casting to
> immutable, that should work..
>
>>
>> But to cast something, you'd need to have access to it in the
>> first place...
>>
>> This seems to work:
>>
>> int function(int) pure my_func_ptr;
>>
>> struct CallImmutable {
>> static opDispatch(string fn, Args...)(Args args) {
>> return mixin(fn)(args);
>> }
>> }
>>
>> int test() pure {
>> return CallImmutable.my_func_ptr(1);
>> }
>>
>> But I suspect it's because of a bug.
>> `CallImmutable.opDispatch` should not be deduced to be pure,
>> and this not be callable from `test`.
>
> Yeah that looks like a bug. I should be able to conjure
> something up, perhaps using assumeUnique, that won't break in
> newer versions.
>
> Thanks for the answers!
Filed as:
https://issues.dlang.org/show_bug.cgi?id=13187
More information about the Digitalmars-d-learn
mailing list