D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6293 - [Regression 2.054] The expression x.y makes the function impure when the 'x' part is not just a variable
Summary: [Regression 2.054] The expression x.y makes the function impure when the 'x' ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
: 6284 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-07-12 01:38 UTC by kennytm
Modified: 2011-08-01 21:45 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-07-12 01:38:45 UTC
Test case
-----------------------
class C6293 {
    int token;
}
struct S6293 {
    const(C6293)[] tokens;
    void f() const pure {
        const(C6293) a = tokens[0];
        int b = a.token;           // <-- separating it is ok.
        int c = tokens[0].token;   // <-- cannot access mutable data 'token'
    }
}
-----------------------
x.d(9): Error: pure nested function 'f' cannot access mutable data 'token'
-----------------------

If that 'b' can be accessed in a 'pure' function, there's no reason 'c' cannot.
Comment 1 kennytm 2011-07-12 13:22:49 UTC
DMD pull #243.

https://github.com/D-Programming-Language/dmd/pull/243
Comment 2 kennytm 2011-07-16 01:04:00 UTC
*** Issue 6284 has been marked as a duplicate of this issue. ***
Comment 3 kennytm 2011-07-16 01:07:42 UTC
Further failing cases:

 * f(x).member
 * (*__withSym).member  (which is what bug 6284 is about)
 * ...

In a DotVarExp, whenever the 'e1' is not a VarExp or a DotVarExp, the purity check will fail even if 'e1' is already verified as pure.