Menu

#908 Access rights of overload For/Next/Step operators not taken into account by For...Loop statement

closed
None
compiler
2020-08-17
2019-08-09
No

The access rights (as private, protected and public) of the overload iterating operators (For, Next and Step) are not taken into account by the For...Loop statement.

By cons (for example), that works well for the overload operators New([]) and Delete([]) when called from New([]) expression and Delete([]) statement.

Example:

Type UDT
  Public:
    Declare Constructor (Byval i As Integer)
    Dim As Integer I
  Private:
    Declare Operator For (Byref iterateStep As UDT)
    Declare Operator Next (Byref iterateCondition As UDT, Byref iterateStep As UDT) As Integer
    Declare Operator Step (Byref step_var As UDT)
End Type

Constructor UDT (Byval i As Integer)
  This.I = i
End Constructor

Operator UDT.For (Byref iterateStep As UDT)
End Operator

Operator UDT.Next (Byref iterateCondition As UDT, Byref iterateStep As UDT) As Integer
  If iterateStep.I >= 0 Then
    Return This.I <= iterateCondition.I
  Else
    Return This.I >= iterateCondition.I
  End If
End Operator

Operator UDT.Step (Byref step_var As UDT)
  This.I += step_var.I
End Operator

For iterator As UDT = UDT(5) To UDT(10) Step UDT(1)  ' expected: error 202: Illegal member access
  Print iterator.I
Next iterator

Sleep

Discussion

  • Jeff Marshall

    Jeff Marshall - 2020-08-17
    • status: open --> closed
    • assigned_to: Jeff Marshall
     

Log in to post a comment.