www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12807] New: UFCS checks "alias this" attributes even when not


          Issue ID: 12807
           Summary: UFCS checks "alias this" attributes even when not
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: monarchdodra gmail.com

Basically, if you call a function "UFCS style", on an object that has an alias
this, then the compiler (from what I can observe) will consider the "alias
this" as "called" to evaluate the attributes, even if the alias this is not
actually called. Example:

void foo(T)(ref T t) 
    pragma(msg, T.stringof);

struct S
    int impure() {assert(0);}
    alias impure this;

void main() pure
    S s; 
    foo(s);  //YES
    s.foo(); //NO
Error: pure function 'D main' cannot call impure function 'main.S.impure'

What's "funny" is that is you remove the "pure" on main, we can verify that
"impure" is never actually called.

Discovered while writing:

assert(!source.doesPointTo(source), "msg");
Worked around with:
assert(!doesPointTo(source, source), "msg");

May 26 2014