redscript icon indicating copy to clipboard operation
redscript copied to clipboard

Private visibility of method not honored in subclass

Open shiide opened this issue 2 years ago • 3 comments

I accidentally left a private modifier on a method that is added to an existing CP77 class, this method is then called by its subclasses. To my surprise this works, although the visibility should be at least protected (at least by my assumption).

shiide avatar Jan 09 '23 19:01 shiide

Visibility has never been enforced on accessing class members, because initially, when building the compiler I realized that it severely limited what kinds of mods could be written without accessing bits of the game that were made private by CDPR. I've been considering to include some opt-in mechanism to enable visibility enforcement for your own classes, but it's not been added yet - the only visibility that is currently enforced is for module imports/exports.

jac3km4 avatar Jan 10 '23 21:01 jac3km4

We can keep this issue as an enhancement (addition of an opt-in visibility enforcement for class members).

jac3km4 avatar Jan 10 '23 21:01 jac3km4

Thanks, makes sense.

The opt-in enforcement for user types sounds great.

shiide avatar Jan 11 '23 10:01 shiide