const(int) cannot be sent as int message

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 30 17:01:40 PDT 2016


As expected, the following trivial case works:

void main() {
     auto func = delegate(int i) {};  // expects int

     func(const(int)(42));            // passes const(int)
}


The following concurrency program fails at runtime:

import core.thread;
import std.concurrency;

void foo() {
     receiveOnly!int();            // expects int
}

void main() {
     auto worker = spawn(&foo);

     // Sends const(int)
     worker.send(const(int)(42));  // sends const(int)

     thread_joinAll;
}

std.concurrency.MessageMismatch at std/concurrency.d(224): Unexpected 
message type: expected 'int', got 'const(int)'


Feature or bug? (receive() is worse because as it simply ignores the 
message.)

Ali


More information about the Digitalmars-d-learn mailing list