Bug 12912 – Lambda function is incorrectly inferred as impure if it uses member field or function

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-13T10:07:00Z
Last change time
2015-02-18T03:37:35Z
Keywords
rejects-valid
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2014-06-13T10:07:38Z
This code should compile: --- struct S(alias fun) { void f() { fun(); } } class C { int n; void f() pure { S!(() => n) s; // `() pure => n` works s.f(); // line 11 } } --- main.d(11): Error: pure function 'main.C.f' cannot call impure function 'main.C.f.S!(delegate () => this.n).S.f' --- This breaks lots of `std.algorithm` usages in `pure` functions.
Comment #1 by k.hara.pg — 2014-06-14T12:03:36Z
This is not a regression, and a dup of issue 9148. *** This issue has been marked as a duplicate of issue 9148 ***
Comment #2 by verylonglogin.reg — 2014-08-10T13:12:49Z
(In reply to Kenji Hara from comment #1) > This is not a regression, and a dup of issue 9148. > > *** This issue has been marked as a duplicate of issue 9148 *** Effectively this is a regression as this code used to work fine: --- import std.algorithm; import std.array; auto makeInoutArray(alias func, T)(inout T[] src) { return cast(inout) func(cast(T[]) src).array(); } final class C { int f(in uint) pure inout { return 1; } } final class C2 { C[] cs; uint var; void f() pure inout { cs.makeInoutArray!(arr => arr .map!((c) /*pure*/ => c.f(var))() )(); } } --- It may be called a Phobos regression or whatever but it does break code. How should we deal with such situations, when some bugs prevented some checks and both correct and incorrect code worked, but introduced fixes rejected both correct and incorrect codes?
Comment #3 by github-bugzilla — 2014-11-13T10:59:26Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/79d4d2c038dfd63cebb6c892444000e96bfb1621 fix Issue 12912 - Lambda function is incorrectly inferred as impure if it uses member field or function
Comment #4 by github-bugzilla — 2015-02-18T03:37:35Z
Commit pushed to 2.067 at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/79d4d2c038dfd63cebb6c892444000e96bfb1621 fix Issue 12912 - Lambda function is incorrectly inferred as impure if it uses member field or function