[Issue 9230] New: Incorrect implicit immutable conversion occurs in pure function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 27 19:02:26 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9230

           Summary: Incorrect implicit immutable conversion occurs in pure
                    function
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-12-27 19:02:24 PST ---
From: http://d.puremagic.com/issues/show_bug.cgi?id=6553

In git head, following code compiles without errors, and asserts in runtime.

string foo(in char[] s) pure {
    return s; // conversion from const(char[]) to string
}
void main() {
    char[] buf = ['a'];
    immutable str = foo(buf);
    assert(str[0] == 'a');
    buf[0] = 'b';
    assert(str[0] == 'a');  // fails!?
}

There is a problem on the return statement in foo. Complier deduces foo to a
strong purity function, but its parameter s might refer outer mutable state, so
the conversion const(char[]) to string should not be applied.

This is an implementation bug of issue 5081.

https://github.com/D-Programming-Language/dmd/commit/99e0f21d2a7a19b655d97fa08394a3bc623f10a0

https://github.com/D-Programming-Language/dmd/commit/99e0f21d2a7a19b655d97fa08394a3bc623f10a0#L3R3524

The implicit immutable conversion on return statement is valid only if the
strong purity function has *no parameters*.

This bug has appeared by the purity calculation improvement by issue 8408.

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


More information about the Digitalmars-d-bugs mailing list