std.string.assumeUTF() silently casting mutable to immutable?
    Forest 
    forest at example.com
       
    Tue Feb 13 07:40:57 UTC 2024
    
    
  
I may have found a bug in assumeUTF(), but being new to D, I'm 
not sure.
The description:
> Assume the given array of integers arr is a well-formed UTF 
> string and return it typed as a UTF string.
> ubyte becomes char, ushort becomes wchar and uint becomes 
> dchar. Type qualifiers are preserved.
The declaration:
```d
auto assumeUTF(T)(T[] arr)
if (staticIndexOf!(immutable T, immutable ubyte, immutable 
ushort, immutable uint) != -1)
```
Shouldn't that precondition's `immutable T` be simply `T`?
As it stands, I can do this with no complaints from the 
compiler...
```d
string test(ubyte[] arr)
{
     import std.string;
     return arr.assumeUTF;
}
```
...and accidentally end up with a "string" pointing at mutable 
data.
Am I missing something?
    
    
More information about the Digitalmars-d-learn
mailing list