Problems with receive

Stanislav Blinov stanislav.blinov at gmail.com
Mon Aug 30 13:21:31 PDT 2010


Philippe Sigaud wrote:
>         static assert( a1.length != 1 || !is( a1.field[0] == Variant ),
> 
>  
> 
>     Is that so? I thought ParameterTypeTuple and Tuple are different.
> 
> 
> You're right, there are different. ParameterTypeTuple is a type tuple (a 
> bunch of types grouped together, with indexing and length, like an 
> array). Tuple is a struct wrapping a type tuple, which can be exposed 
> through the .field member.
> 
> In the above line, since a1 is a ParameterTypeTuple, it has no .field 
> member. In effect the expression a1.field[0] == Variant has no 
> meaningful type and so is(...) is always false. Hence, || !is(...) is 
> like || true. It disables the second part of the test.

Thanks, I thought I'm at a loss.

> 
> As for std.concurrency, I never looked at the code before, but the point 
> of receive() seems to do compile-time checking on the matching functions 
> before calling mbox.get( ops ), it's a good idea to put make the if 
> statement a static if: all other constructs in there are done 
> compile-time, I'd guess.

Yes, that's it. And one (final from me :) ) proposed fix for current 
Phobos would be this:

The mentioned line (384) of std.concurrency should read:

static assert( !T[i+1..$].length || a1.length != 1 || !is( a1[0] == 
Variant ),

The error occurs currently because function parameter is enforced NOT to 
be a Variant even for last function in the list (because of i < T.length 
  on line 382). Thus, assert triggers no matter where in receive() do 
you insert a Variant handler. Proposed workaround should overcome this 
by adding additional condition that currently examined handler is not 
the last one in the list.


More information about the Digitalmars-d-learn mailing list