Bug 10614 – A delegate erroneously inferred as impure

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-07-11T12:17:00Z
Last change time
2015-03-25T05:14:08Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-07-11T12:17:22Z
struct Foo { immutable int y; void bar(TF)(TF f) pure { f(1); } void spam() pure { bar((int x) => y); } } void main() {} dmd 2.064alpha gives errors, but I think the code should be accepted: test.d(4): Error: pure function 'test.Foo.bar!(immutable(int) delegate(int x) nothrow @safe).bar' cannot call impure delegate 'f' test.d(7): Error: template instance test.Foo.bar!(immutable(int) delegate(int x) nothrow @safe) error instantiating
Comment #1 by k.hara.pg — 2015-03-25T05:14:08Z
(In reply to bearophile_hugs from comment #0) > struct Foo { > immutable int y; > void bar(TF)(TF f) pure { > f(1); > } > void spam() pure { > bar((int x) => y); > } > } > void main() {} By fixing issue 9148, a lambda (int x) => y is deduced to weak purity. Therefore its call will be accepted in bar. Will be fixed 2.067 and later. *** This issue has been marked as a duplicate of issue 9148 ***