Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

Using user-defined public namespace in class level

Open ylazy opened this issue 7 months ago • 2 comments

Currently a user-defined public namespace can only be used in properties/methods.

This code:

use namespace my_namespace;

my_namespace class ClassName // Error: A user-defined namespace attribute can only be used at the top level of a class definition.
{
}

will throw an Error: A user-defined namespace attribute can only be used at the top level of a class definition.

Is this possible? I'm not the only one who needs it.

Thanks!

ylazy avatar Apr 16 '25 11:04 ylazy

Why do I need it?

I want to hide some classes (including interfaces) but still use them where I need them. With this feature, I can split a large library into smaller parts, each part having a unique namespace. This allows for better class organization and helps my IDE work faster.

ylazy avatar Apr 16 '25 11:04 ylazy

Interesting use case .. so just to confirm, that's a compile-time error, so it's the compiler that's saying that this isn't supported.

Looking at the AVM2 Overview document, an "instance" has a name which is a QName; the members are then defined by traits that also have a QName as a name. And a QName is basically a pairing of a namespace with a name.

So I don't see why it's not possible to have that apply to class or interface definitions in the same way as it applies to class/instance properties or methods. It may just be a case of getting the compiler to spit out the right ABC for it...

ajwfrost avatar Apr 16 '25 14:04 ajwfrost