digitalmars.D - Is it intentional that forward references in unittests aren't
- Trass3r (23/23) Jun 03 2010 void main()
- Ellery Newcomer (3/24) Jun 03 2010 It's intentional. Forward references generally aren't allowed inside
- bearophile (7/19) Jun 03 2010 Being unittests functions, it can be better to use "static struct" there...
- retard (3/27) Jun 03 2010 What does this mean? Can't you write a wrapper struct/class inside the
- bearophile (6/8) Jun 03 2010 Seen from a high level a unittest section != function. But in D they are...
- Steven Schveighoffer (12/39) Jun 04 2010 When compiling unittests, the version 'unittest' is defined, so somethin...
- Steven Schveighoffer (7/30) Jun 04 2010 unittest is a function. It's basically a single function per module tha...
void main() { } unittest { struct S { S2 s; } struct S2 { } S s; } yields: unittests.d(9): Error: identifier 'S2' is not defined unittests.d(9): Error: S2 is used as a type unittests.d(8): Error: no size for type _error_ Error: no size for type _error_ while putting S2 in front of S works makes it work. Is this intentional?
Jun 03 2010
On 06/03/2010 05:04 PM, Trass3r wrote:void main() { } unittest { struct S { S2 s; } struct S2 { } S s; } yields: unittests.d(9): Error: identifier 'S2' is not defined unittests.d(9): Error: S2 is used as a type unittests.d(8): Error: no size for type _error_ Error: no size for type _error_ while putting S2 in front of S works makes it work. Is this intentional?It's intentional. Forward references generally aren't allowed inside function bodies.
Jun 03 2010
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. Bye, bearophile
Jun 03 2010
Thu, 03 Jun 2010 18:30:04 -0400, bearophile wrote:Trass3r: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.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.
Jun 03 2010
retard: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.Seen from a high level a unittest section != function. But in D they are implemented as a kind-of-function anyway. So unittests in D2 can show some unwanted characteristics that are present in functions. This means that they are an abstraction that "leaks" (a bit): http://en.wikipedia.org/wiki/Leaky_abstraction But I have not criticized this design choice because overall the alternatives can be worse. Bye, bearophile
Jun 03 2010
On Thu, 03 Jun 2010 20:44:00 -0400, retard <re tard.com.invalid> wrote:Thu, 03 Jun 2010 18:30:04 -0400, bearophile wrote:When compiling unittests, the version 'unittest' is defined, so something like this should work: version(unittest) { struct S { S2 s; } struct S2 {} } -SteveTrass3r: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.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.
Jun 04 2010
On Thu, 03 Jun 2010 18:04:26 -0400, Trass3r <un known.com> wrote:void main() { } unittest { struct S { S2 s; } struct S2 { } S s; } yields: unittests.d(9): Error: identifier 'S2' is not defined unittests.d(9): Error: S2 is used as a type unittests.d(8): Error: no size for type _error_ Error: no size for type _error_ while putting S2 in front of S works makes it work. Is this intentional?unittest is a function. It's basically a single function per module that is a concatenation of all the unit tests in the module. Inside functions, forward references are not allowed. You can declare types or include imports using version(unittest) and then forward references should work. -Steve
Jun 04 2010