Bug 8446 – Can't use 'this' pointer in pure member function?

Status
RESOLVED
Resolution
INVALID
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-26T13:53:00Z
Last change time
2012-11-09T10:50:40Z
Assigned to
nobody
Creator
dmitry.olsh

Comments

Comment #0 by dmitry.olsh — 2012-07-26T13:53:25Z
A test case, probably can be reduced futher: @trusted public struct RleBitSet(T) { public: @property auto byInterval() pure const { static struct IntervalRange { this(in RleBitSet set_) { } } return IntervalRange(this); } } immutable set = RleBitSet!(uint).init; pure void func() { auto x = set.byInterval; } Tested on DMD 2.060 beta. Compiler flags seem to have no effect. Output: bug.d(14): Error: pure function 'byInterval' cannot call impure function 'this'
Comment #1 by k.hara.pg — 2012-11-08T22:36:15Z
(In reply to comment #0) This is a trivial bug of the original code. > @property auto byInterval() pure const > { > static struct IntervalRange > { this(in RleBitSet set_) // should be pure > { > } > } return IntervalRange(this); // needs pure constructor > }
Comment #2 by dmitry.olsh — 2012-11-09T10:50:40Z
(In reply to comment #1) > (In reply to comment #0) > > This is a trivial bug of the original code. > > > @property auto byInterval() pure const > > { > > static struct IntervalRange > > { > this(in RleBitSet set_) // should be pure > > { > > } > > } > return IntervalRange(this); // needs pure constructor > > } Thanks, it's indeed obvious from the perspective. But since this was a parameter, it didn't occur to me it means constructor of IntervalRange that is not pure. Must have been angry already. I'd still argue that error message is not helpful. Error: pure function 'byInterval' cannot call impure function 'this' There is no idication of which 'this' it talks about. Would it be better if it listed IntervalRange.this?