Page MenuHomeFeedback Tracker

Enscript does not care for accessibility when overriding functions
Closed, ResolvedPublic

Description

As the title says,

class AA {
	protected void Fun() {}
}
class BB : AA {
	override void Fun() {} // should throw compile error for inconsistent accessibility.
}
AA a = new AA();
BB b = new BB();
AA upcasted = (AA)b;
a.Fun(); // compile error.
b.Fun(); // ok, instead, should throw compile error.
upcasted.Fun(); // the object is of type BB, but casted to AA, compile error.

Also this code causes a crash if you put the last six lines into a non-member function. In the repro code, as you can see I put it in a member function instead, which causes no crash, if I were to remove the class, and just leave the function, the workbench crashes, all I know for now is that this is due to 'protected' modifier in the AA class.

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

Compile

class AA {
	protected void Fun() {}
}
class BB : AA {
	override void Fun() {}
}

class Repro {
	void Fun() {
		AA a = new AA();
		BB b = new BB();
		AA upcasted = (AA)b;
		a.Fun();
		b.Fun();
		upcasted.Fun();
	}
}

As said in the description, the below code crashes the workbench.

class AA {
	protected void Fun() {} // removing protected prevents the crash.
}
class BB : AA {
	override void Fun() {}
}


void Fun() {
	AA a = new AA();
	BB b = new BB();
	AA upcasted = (AA)b;
	a.Fun();
	b.Fun();
	upcasted.Fun();
}

Event Timeline

sharp1337 updated the task description. (Show Details)Aug 25 2022, 5:57 PM
sharp1337 edited Steps To Reproduce. (Show Details)
sharp1337 edited Steps To Reproduce. (Show Details)
sharp1337 edited Steps To Reproduce. (Show Details)
Geez changed the task status from New to Awaiting internal Testing.Aug 30 2022, 12:34 PM
Geez closed this task as Resolved.Nov 10 2022, 2:52 PM
Geez claimed this task.
Geez added a subscriber: Geez.

Hello sharp1337.
The crash issue has been fixed internally. In regards to everything else, it seems to work as designed.
Regards,
Geez