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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 27 21:47:34 PST 2012


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


yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies at gmail.com


--- Comment #3 from yebblies <yebblies at gmail.com> 2012-12-28 16:47:33 EST ---
(In reply to comment #0)
> 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.
> 
> This bug has appeared by the purity calculation improvement by issue 8408.

The patch for issue 5081 was corrent, the problem is that the definition of
strong purity has been changed since then.

(In reply to comment #1)
> (In reply to comment #0)
> > The implicit immutable conversion on return statement is valid only if the
> > strong purity function has *no parameters*.
> 
> ...No, this is incorrect. I found a disproof.
> 
> Correct requirement is:
> "If all parameters have no mutable indirections, implicit immutable conversion
> on return statement is allowed."
> 

This is the old definition of strong purity.

-- 
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