Send/Receive bug in std.concurrency with immutable(ubyte[]) ?

Paul Backus snarwin at gmail.com
Sun Aug 4 14:29:05 UTC 2019


On Sunday, 4 August 2019 at 13:57:14 UTC, Vijay Nayar wrote:
> import std.concurrency;
> import std.stdio;
>
> void testThread() {
>   receive(
>       (immutable(ubyte[]) data) => writeln("Got it!"),
>       (Variant v) => writeln("Mismatch: ", v.type()));
> }
>
> void main() {
>   immutable(ubyte[]) data = [1, 2, 3];
>   auto tid = spawn(&testThread);
>   send(tid, data);
> }
>
> The output of this program is:
>   Mismatch: immutable(ubyte)[]
>
> Why does calling send with data of type immutable(ubyte[]) get 
> converted to immutable(byte)[] when it is called with 
> std.concurrency's send() and receive().  Is this a bug?

immutable(T[]) "decays" to immutable(T)[] when passed to a 
function (most of the time [1]):

import std.stdio;

void checkType(T)(T arg) { writeln(typeof(arg).stringof); }

void main()
{
     immutable(ubyte[]) a;
     checkType(a); // immutable(ubyte)[]
}

[1] https://issues.dlang.org/show_bug.cgi?id=18268


More information about the Digitalmars-d mailing list