Error "Outer Function Context is Needed" when class declared in unittest

Vijay Nayar madric at gmail.com
Thu Jan 5 16:38:49 UTC 2023


On Thursday, 5 January 2023 at 13:47:24 UTC, Adam D Ruppe wrote:
> On Thursday, 5 January 2023 at 13:27:23 UTC, Vijay Nayar wrote:
>> Why is this error only found when declaring a class in the 
>> unittest?
>
> A unittest is just a special function, it can run code and have 
> local variables.
>
> classes and structs declared inside it have access to those 
> local contexts, which it calls the outer function context.
>
> Make the outer class `static` too to lift it out of this and 
> your error should go away.

That's very informative, I didn't realize that `unittest` is 
actually a function.

It raises another question one step deeper, what does it mean to 
define a non-static class within a function? Does that class 
inherit the scope of the function it is inside, similar to how an 
inner class does with an outer class?


More information about the Digitalmars-d-learn mailing list