D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6265 - Pure-inference failed when calling other pure functions
Summary: Pure-inference failed when calling other pure functions
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Mac OS X
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-07-07 10:24 UTC by kennytm
Modified: 2011-08-12 00:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-07-07 10:24:42 UTC
Test case:

----------------------
pure int h() {
    return 1;
}
int f(alias g)() {
    return g();
}
pure int i() {
    return f!h();
}
----------------------
x.d(8): Error: pure function 'i' cannot call impure function 'f'
----------------------

The instantiation f!h should be detected as pure, but currently DMD on git master fails to do so.

nothrow and @safe are correctly inferred.
Comment 1 kennytm 2011-07-07 13:40:50 UTC
Actually the problem is not due to the template alias parameter, but because 'CallExp::semantic' calls 'Expression::checkPurity' which calls 'FuncDeclaration::isPure' on the outer function, and stops its inference with 'setImpure'.



Two more test cases:

------------------------
pure int h() {
    return 1;
}
int f()() {
    return h();
}
pure int i() {
    return f();
}
-------------------------


-------------------------
pure int h() {
    return 1;
}
pure int i() {
    return {
        return h();
    }();
}
-------------------------
Comment 2 kennytm 2011-07-09 11:06:14 UTC
DMD pull #222.

https://github.com/D-Programming-Language/dmd/pull/222