Bugzilla – Bug 6188
Cyclical methodmap references
Last modified: 2017-08-04 18:43:04 PDT
Would it be possible to introduce cyclical methodmap references? I know that the transitional API wiki page states "methodmaps must be declared before they are used.", but can this restriction be easily worked around? For instance, a methodmap layout like this is impossible to implement, but would be very useful: methodmap Player { public Weapon GetWeapon() { return Weapon:1; } }; methodmap Weapon { public Player GetOwningPlayer() { return Player:1; } }; In C/C++, this is worked around with forward declarations, whereas in C# the declaration order doesn't matter to the compiler. Would one of these options be feasible?
If you don't need anything fancier, you can forward-declare the tags by doing: enum Weapon: {}; (The : after "Weapon" adds the tag without creating an actual empty enum-struct.) Otherwise... if for example GetWeapon needs to construct an actual weapon via its constructor, that entrains the exact same problems as the other bug you mentioned involving use-before-declaration. It's feasible, but complicate.
(In reply to David Anderson [:dvander] from comment #1) Ideally I'd like to be able to construct using Weapon, but being able to forward declare the Weapon tag can work for now. The only problem when doing this is a tag mismatch warning when retagging `Weapon:1`: enum Weapon: {}; methodmap Player { public Weapon GetWeapon() { // warning 213: tag mismatch return Weapon:1; } }; methodmap Weapon { public Player GetOwningPlayer() { return Player:1; } };
Yeah, I agree it's gross. I'll think about how to approach this though I don't think I'll tackle it immediately.
I've come up with a (gross) workaround, but I still get the missing tags warning https://forums.alliedmods.net/showthread.php?t=300065 Hope this gets fixed
I started a patch to do this forever ago, but forgot about it. Bother me on IRC in like a week if I haven't finished it. I think the incomplete work is a PR currently.