paul doe wrote: ↑Apr 20, 2022 16:16
Protected can be understood as 'public for the class and derived classes', but this is clearly not the case and it is, thus, a bug as far as I can tell. I double checked the behavior with C++, Java, PHP, C# and Visual Basic. They all work as expected (ie protected NOT being accessible from client code)
Indeed, I think this behavior (when the access operator does not apply on the non-static 'This' instance, explicitly or implicitly) would deserve a discussion, perhaps here ?
Code: Select all
Type Parent
Protected:
Dim As Integer I
Static As Integer J
End Type
Dim As Integer Parent.J
Type Child1 Extends Parent
End Type
Type Child2 Extends Parent
Declare Sub test(Byref c2 As Child2, Byref p As Parent, Byref c1 As Child1)
Declare Static Sub stest(Byref c2 As Child2, Byref p As Parent, Byref c1 As Child1)
End Type
Sub Child2.test(Byref c2 As Child2, Byref p As Parent, Byref c1 As Child1)
' non-static protected member access from non-static member procedure
I = 1 ' OK
This.I = 2 ' OK
c2.I = 3 ' OK, but should be NOK ?
p.I = 4 ' OK, but should be NOK ?
c1.I = 5 ' OK, but should be NOK ?
' static protected member access from non-static member procedure
J = 1 ' OK
This.J = 2 ' OK
c2.J = 3 ' OK
p.J = 4 ' OK
c1.J = 5 ' OK
End Sub
Static Sub Child2.stest(Byref c2 As Child2, Byref p As Parent, Byref c1 As Child1)
' non-static protected member access from static member procedure
c2.I = 3 ' OK, but should be NOK ?
p.I = 4 ' OK, but should be NOK ?
c1.I = 5 ' OK, but should be NOK ?
' static protected member access from static member procedure
J = 1 ' OK
c2.J = 3 ' OK
p.J = 4 ' OK
c1.J = 5 ' OK
End Sub
The definition of 'Protected' in the documentation may appear to be consistent with current behavior, as this definition applies to type hierarchy in general, not to specific instance inheritance (like the other definition proposed in my post above for accessing protected non-static members).
In my opinion, the current behavior is correct for accessing protected static members, but maybe not for accessing protected non-static members.
@
Jeff and others interested, what is your opinion on the 'Protected' access control definition ?