Thread overview
Tango error : cannot modify immutable expression *p++
Sep 10, 2020
jeromeG
Sep 10, 2020
Paul Backus
Sep 11, 2020
Jacob Carlborg
Sep 11, 2020
Jacob Carlborg
September 10, 2020
Hi people,

I am using the tango-1.0.5_2.0.85 package in my project, for some reasons :)

This packages contains tango/tango/text/convert/Float.d

I was just compiling my program and got this error:

../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(251,13): Error: cannot modify immutable expression *p++

In fact, there are a dozen similar errors with Float.d, because the code shows the following in different places:

-----
        auto p = dst.ptr;
        if (sign)
            *p++ = '-'; <<< this is problematic
-----

dst is from the function argument list :

T[] format(T) (T[] dst, NumType x, int decimals=Dec, int e=Exp, bool pad=Pad)


I don't understand why dst is immutable at the first place... I guess the error pops up because the template argument passed as T is immutable itself. But in this case, I don't see how we can return a modified dst at any point.
I try a few Rebindable combos, but a bit randomly, as I don't understand exactly what Rebindable is for. Not to avail.

Compiler output:
-------------------------
$ dub build
Performing "debug" build using /home/jegau/dlang/dmd-2.093.1/linux/bin64/dmd for x86_64.
diamond ~master: building configuration "library"...
src/diamond/core/misc.d(177,27): Error: undefined identifier doFormat in module std.format
src/diamond/gui/surfacegeometry.d(163,13): Warning: ubyte *= float is performing truncating conversion
src/diamond/gui/surfacegeometry.d(174,7): Warning: ubyte *= float is performing truncating conversion
../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(251,13): Error: cannot modify immutable expression *p++
../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(255,20): Error: cannot modify immutable expression *p++
../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(261,15): Error: cannot modify immutable expression *p++
../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(265,18): Error: cannot modify immutable expression *p++
../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(267,25): Error: cannot modify immutable expression *p++
.... (more similar errors)

Any shining light appreciated.



September 10, 2020
On Thursday, 10 September 2020 at 20:55:17 UTC, jeromeG wrote:
> I was just compiling my program and got this error:
>
> ../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(251,13): Error: cannot modify immutable expression *p++
>
> In fact, there are a dozen similar errors with Float.d, because the code shows the following in different places:
>
> -----
>         auto p = dst.ptr;
>         if (sign)
>             *p++ = '-'; <<< this is problematic
> -----
>
> dst is from the function argument list :
>
> T[] format(T) (T[] dst, NumType x, int decimals=Dec, int e=Exp, bool pad=Pad)
>
>
> I don't understand why dst is immutable at the first place...

I haven't used Tango, but my guess is it's because strings are immutable in D2, but used to be mutable in D1.
September 11, 2020
On 2020-09-10 23:00, Paul Backus wrote:

> I haven't used Tango, but my guess is it's because strings are immutable in D2, but used to be mutable in D1.

Tango is compatible with D2. The version of Tango includes the last version of DMD it worked on, in this case 2.085.

-- 
/Jacob Carlborg
September 11, 2020
On 2020-09-10 22:55, jeromeG wrote:
> Hi people,
> 
> I am using the tango-1.0.5_2.0.85 package in my project, for some reasons :)
> 
> This packages contains tango/tango/text/convert/Float.d
> 
> I was just compiling my program and got this error:
> 
> ../../../.dub/packages/tango-1.0.5_2.0.85/tango/tango/text/convert/Float.d(251,13): Error: cannot modify immutable expression *p++
> 
> In fact, there are a dozen similar errors with Float.d, because the code shows the following in different places:
> 
> -----
>          auto p = dst.ptr;
>          if (sign)
>              *p++ = '-'; <<< this is problematic
> -----
> 
> dst is from the function argument list :
> 
> T[] format(T) (T[] dst, NumType x, int decimals=Dec, int e=Exp, bool pad=Pad)
> 
> 
> I don't understand why dst is immutable at the first place... I guess the error pops up because the template argument passed as T is immutable itself. But in this case, I don't see how we can return a modified dst at any point.

I'm guessing `T` should to be `char`. There are some examples at the bottom how to use it:

https://github.com/SiegeLord/Tango-D2/blob/6a9efb86a0789fb2e32ef869e647e7de97b5e26b/tango/text/convert/Float.d#L855

-- 
/Jacob Carlborg