Output contract's arguements
monarch_dodra
monarchdodra at gmail.com
Wed Sep 18 05:11:01 PDT 2013
This came up in learn:
Say you have this code:
//----
size_t msb(T)(T v)
in
{
assert(v != 0);
}
out(ret)
{
assert(v != 0); //Fails? Passes?
}
body
{
size_t ret = 0;
while(v >>= 1) ++ret;
return ret;
}
//----
Question, can this output contract fail?
Apparently, it does fail, since it is passed the variable v,
*after* the body of the function is done with it.
IMO, this is wrong. When calling a function with an out contract,
the arguments should *also* be passed to the out contract
directly. "out" should not be expected to run on the body's
"sloppy seconds".
In particular if/when we will have "contracts are
managed/compiled by caller", then that behavior is the only
behavior we will be able to do (AFAIK).
Or is there something that explicitly states it works that way?
Should I file a bug report? ER?
More information about the Digitalmars-d
mailing list