Page MenuHomeFeedback Tracker

wrong Method is private errors
Assigned, UrgentPublic

Description

I wanted to make more use of the private keyword to restrict access to some of my classes methods, but I noticed, that I get a Method '...' is private quite often when (from my knowledge) this should not be the case. I found two different occurrences when I could not access a private method, even when I wanted to call it from the same class I was in:

  • have a private method in a derived class and overwrite a method from the original class and try to call the private method from the overwritten method
  • have a static method try to access a private method from the same class

Idk if that's intended, but from my view it's not how private should work. The same applies to private variables

Details

Severity
Crash
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Category
General
Steps To Reproduce
class BaseClass {

    void TestMethod() {}

}
class DerivedClass : BaseClass {

    private void ThePrivateMethod() {}

    override void TestMethod() {
        ThePrivateMethod(); // Error, because the Method is private ?
    }

    static DerivedClass FactoryMethod() {
        DerivedClass instance = new DerivedClass();
        instance.ThePrivateMethod(); // Error, because the Method is private ?
        return instance;
    }

}

Event Timeline

LBmaster created this task.Aug 24 2023, 9:32 PM
Geez changed the task status from New to Assigned.Aug 25 2023, 11:37 AM