Thread overview
[Issue 7295] New: Alias This + Pure + pointsTo = rejects-valid
Jan 15, 2012
David Simcha
Jan 15, 2012
David Simcha
Jan 25, 2012
Don
Jan 26, 2012
Walter Bright
January 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7295

           Summary: Alias This + Pure + pointsTo = rejects-valid
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: dsimcha@yahoo.com


--- Comment #0 from David Simcha <dsimcha@yahoo.com> 2012-01-15 08:26:34 PST ---
import std.exception;

struct RefCounted(T) {
    T payload;

    T refCountedPayload() { return payload;}
    alias refCountedPayload this;
}

void main() {
    RefCounted!int x;
    doPure(x);
}

void doPure(ref RefCounted!int lhs) pure {
    std.exception.pointsTo(lhs, lhs);
}

test.d(16): Error: pure function 'doPure' cannot call impure function
'refCountedPayload'

Marking as critical because this breaks std.algorithm.swap for ref counted types, though there may be an easy workaround:  refCountedPayload() should probably be pure.

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



--- Comment #1 from David Simcha <dsimcha@yahoo.com> 2012-01-15 08:27:13 PST ---
One thing I forgot to note:  This bug appears cross-module only.  If I copy and paste pointsTo() into test.d, the bug goes away.

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


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-01-25 12:50:00 PST ---
Reduced test case:
struct S
{
    int member;
    @property ref int refCountedPayload() { return member; }
    alias refCountedPayload this;
}


// If you remove this next line, it works.
void foo(S)(immutable S t, int qq) pure { }
void foo(S)(S s) pure { }

void bar() pure
{
    S b;
    foo!int(b);
}
-------------------

The bug is in template.c, deduceFunctionTemplateMatch().
If a parameter fails to match (the immutable S above), it tries alias this. The
first is to run semantic on the alias this, which causes the error. Those error
messages should be suppressed.

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-01-26 00:45:17 PST ---
https://github.com/D-Programming-Language/dmd/commit/2357f7771b7a5bdd560c2e8e9656d4194e8388d9

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