[Issue 21021] sending a struct containing array using send/receive have problems.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 6 23:51:55 UTC 2020


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

--- Comment #1 from George Toutoungis <georges.toutoungis at gmail.com> ---
Hi the following code have problem.
in the Message struct, if you comment on the field "hello", it works fine.
also if you comment the line "alias h this", also it works fine.
if the size of the array is smaller than 3, also it works fine.
absolutely there is a problem. the same problem exist on dmd and ldc2
hope you find it and and improve the compilers.

here is the code. if you have any question, please do not hesitate.
thanks a lot for the D programming language, it is great "my favorite".

the code:

/////////////////////////////
module test;

import std.concurrency;
import std.stdio: write, writeln, writef, writefln;


struct LimitEntry
{
    int price;
    int quantity;
}

struct Header
{
        int a;
}

struct Message(ITEM_TYPE)
{
        Header       h;

        int          hello;
        int          element;
        ITEM_TYPE[3] array;

        alias h this;
}


alias MessageType = Message!(LimitEntry);

void spawnedFunc()
{
    receive(
        (MessageType m) 
        {
                writeln(m);
        }
    );
}

void main()
{
        auto id = spawn(&spawnedFunc);

        auto message = MessageType();

        message.h.a     = 2;
        message.hello   = 3;
        message.element = 5;
        message.array[0] = LimitEntry(0,0);
        message.array[1] = LimitEntry(1,1);
        message.array[2] = LimitEntry(2,2);

        writeln(message);

        send(id, message);
}
////////////////////////////////////////////

--


More information about the Digitalmars-d-bugs mailing list