This is an old problem that has been around for a long time, but the compiler abort does not show up in all FreeBASIC installs (that is why I have not reported it before).
Type UDT
Declare Operator [](Byval n As Integer) Byref As Ubyte
Dim As Zstring * 10 z
End Type
Operator UDT.[](Byval n0 As Integer) Byref As Ubyte
Return This.z[n0]
End Operator
Operator Len(Byref zo As Const UDT) As Integer
Dim As Integer n
While zo[n] <> 0
n += 1
Wend
Return n
End Operator
Compiler output:
C:\.....\FBIde0.4.6r4_fbc1.10.0\FBIDETEMP.bas(12) error 276: Const UDT cannot invoke non-const method, UDT.operator.(as integer) byref as ubyte in 'While zo <> 0'
Aborting due to runtime error 12 ("segmentation violation" signal)
I see.
Tested
1.05,1.07,1.08,1.09
I get the same error.
Some of the win64 compilers take a few seconds before the error shows, so it is like a freeze.
(Up to 6 or 7 seconds sometimes!)
Appears that there was some missing error recovery in the compiler if the overloaded [] operator procedure was found but the expression to use it could not be built because of the mismatch between const and non-const.
Independently of being correct or usable user code, the compiler itself should not crash. Update is now in fbc/master.
coderJeff wrote: ↑Feb 11, 2023 16:40
Independently of being correct or usable user code, the compiler itself should not crash.
@Jeff,
Another case of "COMPILER ABORTS after issuing a valid error message":
Compiler aborting by runtime error after rejecting the setting of a UDT reference to a temporary instance created by a constructor with optional parameter.
Type UDT
Dim As Integer I
Declare Constructor(Byval nop As Integer = 0)
End Type
Constructor UDT(Byval nop As Integer = 0)
End Constructor
Dim Byref As UDT u = UDT() '' or UDT(123)
Compiler output:
C:\.....\FBIde0.4.6r4_fbc1.10.0\FBIDETEMP.bas(8) error 24: Invalid data types, found ''' in 'Dim Byref As UDT u = UDT() '' or UDT(123)'
Aborting due to runtime error 12 ("segmentation violation" signal)
fxm wrote: ↑Apr 10, 2023 9:05
Compiler aborting by runtime error after rejecting the setting of a UDT reference to a temporary instance created by a constructor with optional parameter
Should we try to allow this? Because when UDT(integer) with non-optional arguments is used gives me an invalid data type. Currently compiler does not try to create a temporary instance in this scenario.
I think reason is:
'Dim Byref As UDT u = ...' expects initializer to be something already allocated
'... = UDT()' expects memory already allocated so it can be passed as hidden this parameter to the constructor.
Otherwise looks like a simple to internal change to provide the missing error recovery.