Bug 6265 – Pure-inference failed when calling other pure functions

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-07-07T10:24:00Z
Last change time
2011-08-12T00:02:20Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
kennytm

Comments

Comment #0 by kennytm — 2011-07-07T10:24:42Z
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 by kennytm — 2011-07-07T13:40:50Z
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 by kennytm — 2011-07-09T11:06:14Z
Comment #3 by bugzilla — 2011-08-12T00:02:20Z