D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8998 - 'inout pure' returns immutable, which in reality is mutable
Summary: 'inout pure' returns immutable, which in reality is mutable
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull
Depends on:
Blocks:
 
Reported: 2012-11-11 15:25 UTC by Ali Cehreli
Modified: 2013-03-03 16:55 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Ali Cehreli 2012-11-11 15:25:20 UTC
class A
{
    int i;
}

class C
{
    A a;

    this()
    {
        a = new A();
    }

    // WRONG: Returns immutable(A)
    immutable(A) get() inout pure
    {
        return a;
    }
}

void main()
{
    auto c = new C;

    immutable(A) imm_a = c.get();
    assert(imm_a.i == 0);

    c.a.i = 100;              // <-- changes immutable(A)
    assert(imm_a.i == 100);   // <-- Oops!
}
Comment 1 yebblies 2013-01-12 08:16:34 UTC
This looks similar to issue 9230.  It it possible this case slipped through the cracks?
Comment 2 Kenji Hara 2013-01-20 08:34:18 UTC
https://github.com/D-Programming-Language/dmd/pull/1519

(In reply to comment #1)
> This looks similar to issue 9230.  It it possible this case slipped through the
> cracks?

No. Essentially, this is a regression which has been caused by fixing issue 7769. See the description in my pull request.
Comment 3 github-bugzilla 2013-03-03 16:07:29 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/49b4d94ce98437f408f6c84b9afc36f141c01d5a
fix Issue 8998 - 'inout pure' returns immutable, which in reality is mutable

By fixing issue 7769 (relax inout rule), we cannot assume a function with inout parameters as PUREstrong, because the return type may not have any inout indirections.