Thread overview | |||||
---|---|---|---|---|---|
|
March 30, 2016 const(int) cannot be sent as int message | ||||
---|---|---|---|---|
| ||||
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@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 |
March 31, 2016 Re: const(int) cannot be sent as int message | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On 3/30/16 8:01 PM, Ali Çehreli wrote:
> 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@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.)
Bug, but probably of the enhancement variety I think (I don't think this is a small project). Receive should canonicalize the input and requested receive type. That is, receiveOnly!(const(int)) should really call receiveOnly!int, and send!(const(int)) should really call send!int.
Generous usage of Unqual should be done here.
-Steve
|
March 31, 2016 Re: const(int) cannot be sent as int message | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 31 March 2016 at 13:47:25 UTC, Steven Schveighoffer wrote:
> Bug, but probably of the enhancement variety I think (I don't think this is a small project). Receive should canonicalize the input and requested receive type. That is, receiveOnly!(const(int)) should really call receiveOnly!int, and send!(const(int)) should really call send!int.
>
> Generous usage of Unqual should be done here.
>
> -Steve
Doesn't receive use Algebraic under the hood? I know that Algebraic has various issues with const and immutable types that I run into every once and awhile.
|
Copyright © 1999-2021 by the D Language Foundation