"error 202: Illegal member access, UDT.operator.cast" (it is declared private), but on the other hand this cast() operator is not really called if it is declared public.
For a construction with implicit initialization ('Dim As UDT u = v'), the compiler looks for:
- First a matching constructor (for u type).
- Then else a matching cast() operator (for v type).
In the following oversimplified example (with 'Dim As UDT u2 = u1'), there is not a direct match constructor (the copy-constructor), but a cast() operator that matches another constructor (the conversion-constructor via the String datatype), so both are called:
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String)
' Declare Constructor(Byref t As UDT)
Declare Constructor()
' Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String)
Print "Constructor UDT(Byref As String)", @This
End Constructor
'Constructor UDT(Byref t As UDT)
' Print "Constructor UDT(Byref As UDT)", @This
'End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
Code: Select all
Constructor UDT() 6421976
Operator UDT.Cast() As String 6421976
Constructor UDT(Byref As String) 6421968
If the cast() operator is declared private, the "illegal member access" compiler error message is well obtained:
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String)
' Declare Constructor(Byref t As UDT)
Declare Constructor()
Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String)
Print "Constructor UDT(Byref As String)", @This
End Constructor
'Constructor UDT(Byref t As UDT)
' Print "Constructor UDT(Byref As UDT)", @This
'End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
C:\.....\FBIDETEMP.bas(29) error 202: Illegal member access, UDT.operator.cast in 'Dim As UDT u2 = u1'
Now, a direct match constructor (the copy-constructor) is added to the existing code. It is rightly called, instead of the cast() operator + other constructor (previously both called):
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String)
Declare Constructor(Byref t As UDT)
Declare Constructor()
' Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String)
Print "Constructor UDT(Byref As String)", @This
End Constructor
Constructor UDT(Byref t As UDT)
Print "Constructor UDT(Byref As UDT)", @This
End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
Code: Select all
Constructor UDT() 6421976
Constructor UDT(Byref As UDT) 6421968
But If the cast() operator is again declared private, the "illegal member access" compiler error message is abnormally obtained:
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String)
Declare Constructor(Byref t As UDT)
Declare Constructor()
Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String)
Print "Constructor UDT(Byref As String)", @This
End Constructor
Constructor UDT(Byref t As UDT)
Print "Constructor UDT(Byref As UDT)", @This
End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
C:\.....\FBIDETEMP.bas(29) error 202: Illegal member access, UDT.operator.cast in 'Dim As UDT u2 = u1'
More generally, this bug also appears if it exists a constructor that has as first parameter type the one of the cast() operator, whatever its other parameters.
In this case, the cast() operator is never called, even without copy-constructor (I suppose implicit construction + implicit copy):
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String, Byval i As Integer)
Declare Constructor()
' Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String, Byval i As Integer)
Print "Constructor UDT(Byref As String, Byval As Integer)", @This
End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
Code: Select all
Constructor UDT() 6421976
However when the cast() operator is declared private, the same illicit compiler error message is obtained:
Code: Select all
Type UDT
Public:
Dim As Integer i
Declare Constructor(Byref s As String, Byval i As Integer)
Declare Constructor()
Private:
Declare Operator Cast() As String
End Type
Constructor UDT()
Print "Constructor UDT()",, @This
End Constructor
Constructor UDT(Byref s As String, Byval i As Integer)
Print "Constructor UDT(Byref As String, Byval As Integer)", @This
End Constructor
Operator UDT.Cast() As String
Print "Operator UDT.Cast() As String", @This
Return ""
End Operator
Dim As UDT u1
Print
Dim As UDT u2 = u1
Sleep
C:\.....\FBIDETEMP.bas(24) error 202: Illegal member access, UDT.operator.cast in 'Dim As UDT u2 = u1'
Note:
I found this bug in much more complex code which I simplified as I went along.