Forward Reference Error in unittests

mipri mipri at minimaltype.com
Tue Dec 3 10:30:34 UTC 2019


On Tuesday, 3 December 2019 at 08:48:47 UTC, rbscott wrote:
> Hello,
>
> I was using a unittest to test a mixin that creates a class 
> inside of a struct and I ran into an unexpected error. I 
> removed all of the templates and simplified it down to this 
> case:
>
> unittest {
>   static struct SimpleStruct {
>     static class NestedClass {
>       private SimpleStruct value;
>     }
>   }
> }

Unit tests are special functions, and their contents have
the same restrictions of functions, which seem to include
a ban on forward references (there's a reference in a comment
in https://dlang.org/spec/function.html#nested but I don't
have a better citation).

Likewise this fails, but would succeed if foo were moved
out of the unit test:

unittest {
     void foo(int x) { writeln(x); }

     42.foo;
}



More information about the Digitalmars-d mailing list