Is it intentional that forward references in unittests aren't
Steven Schveighoffer
schveiguy at yahoo.com
Fri Jun 4 04:58:31 PDT 2010
On Thu, 03 Jun 2010 20:44:00 -0400, retard <re at tard.com.invalid> wrote:
> Thu, 03 Jun 2010 18:30:04 -0400, bearophile wrote:
>
>> Trass3r:
>>
>>> void main()
>>> {
>>> }
>>>
>>> unittest
>>> {
>>> struct S
>>> {
>>> S2 s;
>>> }
>>
>> Being unittests functions, it can be better to use "static struct" there
>> instead of "struct".
>>
>> -------------------------
>>
>> Ellery Newcomer:
>>> It's intentional. Forward references generally aren't allowed inside
>>> function bodies.
>>
>> Unittests being normal functions is an abstraction that leaks a bit, but
>> I presume it's OK.
>
> What does this mean? Can't you write a wrapper struct/class inside the
> block if you don't want to expose S and S2 outside the unittest block.
When compiling unittests, the version 'unittest' is defined, so something
like this should work:
version(unittest)
{
struct S
{
S2 s;
}
struct S2 {}
}
-Steve
More information about the Digitalmars-d
mailing list