Macro access control typePath

Hej !

How can I return a macro new $myTypePath(); while this one is private please ?
I’ve tried using @:allow( )without success.


You mean you have a private class?

Those are not visible from another file at all, and even from the same file it doesn’t work in metas like allow.

Is the code returned from the macro added in the same file as the private class?

No, the class is public but the constructor is private.

Easier in that case.

@:allow should go on the private function with the argument being the class which calls it, maybe you did the other way around?

You could also use macro @:privateAccess new $myTypePath();.

1 Like

Thanks Valentin,
I just confused @:allow with @:privateAccess
And it was not @:allow but @:access…

BTW, why @:access didn’t work here please ?

In your case @:allow should be placed on the private constructor and should reference a symbol, which you want to allow access to the constructor.

And @:access is the opposite: place it on the symbol and reference the constructor.

Yes Aleksandr, that what I wrote, I used @:access and not @:allow.
And then, I ask BTW, why this : @:allow( ) didn’t work ?
In this return macro @:access( ) new $myTypePath();

Because you need access here, allow goes on the private constructor to whitelist the places which can ignore the private modifier.

Sorry, I wrote too fast : I used “access” and not “allow” ! And with access it didn’t work !
I’m sorry, I melanged-the-pinceaux lol

Because @:allow and @:access are metas to be used on class fields or types.
While @:privateAccess is a meta to be used on expression level.

1 Like

Ok, thanks, now I understand… It’s hard sometimes to know which meta goes on expression level and which one not