[Issue 7492] [CTFE] Error at assign to immutable character array

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jan 20 10:14:23 PST 2015


https://issues.dlang.org/show_bug.cgi?id=7492

Denis Shelomovskij <verylonglogin.reg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from Denis Shelomovskij <verylonglogin.reg at gmail.com> ---
(In reply to Kenji Hara from comment #2)
> (In reply to Denis Shelomovskij from comment #0)
> > ---
> > auto f() { return new char[1];  }
> > 
> > immutable s = f(); // error, works with non-character arrays
> > ---
> > Error: cannot implicitly convert expression ("\xff") of type char[] to
> > immutable(char[])
> 
> The function returns char[]. In D type system, char[] to immutable(char[])
> conversion is not allowed.
> 
> If you annotate the function f with pure attribute, f() will return an
> unique array so compiler will allow the conversion.
> 
> Anyway, this is not CTFE problem. The code is trying to violate D type
> system, and compiler reports the error correctly.

If function is executed during CTFE it's definitely effectively `pure` for
given parameters so I don't understand your arguments.

Anyway "works with non-character arrays" comment isn't addressed. Event if this
compiler error is an expected behaviour, the issue is in the fact other types
don't produce the same error (try e.g. `int` and `Object` arrays).

--


More information about the Digitalmars-d-bugs mailing list