`static` function ... cannot access variable in frame of ...

user1234 user1234 at 12.de
Mon Jan 15 18:43:43 UTC 2024


On Monday, 15 January 2024 at 18:16:44 UTC, Bastiaan Veelo wrote:
> [...]
>
> It seems to me this should just work.
>
> Thanks!
>
> --Bastiaan.

The two calls are not equivalent. To be equivalent you need to 
set `S_foo` static too, otherwise `S_Foo` is instanciated in 
`main` scope, proof:

```d
import std.stdio;

struct S
{
     static void foo(alias len)()
     {
         writeln(len);
     }
}

static void S_foo(alias len)()
{
     writeln(len);
}

void main()
{

     const five = 5;
     S_foo!five;	// Error too now
     S.foo!five; // Error
}
```

so what is passed as alias need to be static too.

But to be frank, I agree this is a less ideal situation. There 
are like 20 bugs reports opened related to that. The way a 
non-static `S_foo` behaves is under-specified.


More information about the Digitalmars-d-learn mailing list