Bug 7295 – Alias This + Pure + pointsTo = rejects-valid

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2012-01-15T08:26:00Z
Last change time
2012-01-26T00:45:17Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha
Blocks
7296

Comments

Comment #0 by dsimcha — 2012-01-15T08:26:34Z
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.
Comment #1 by dsimcha — 2012-01-15T08:27:13Z
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.
Comment #2 by clugdbug — 2012-01-25T12:50:00Z
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.
Comment #3 by bugzilla — 2012-01-26T00:45:17Z