Thread overview
[Issue 8446] New: Can't use 'this' pointer in pure member function?
Jul 26, 2012
Dmitry Olshansky
Nov 09, 2012
Kenji Hara
Nov 09, 2012
Dmitry Olshansky
July 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8446

           Summary: Can't use 'this' pointer in pure member function?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dmitry.olsh@gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2012-07-26 13:53:25 PDT ---
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'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8446


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com
           Severity|normal                      |blocker


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8446


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-11-08 22:36:15 PST ---
(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
>    }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8446



--- Comment #2 from Dmitry Olshansky <dmitry.olsh@gmail.com> 2012-11-09 10:50:40 PST ---
(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?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------