COMPILER ABORTS after issuing a valid error message

General FreeBASIC programming questions.
Post Reply
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

COMPILER ABORTS after issuing a valid error message

Post by fxm »

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).

Test code:

Code: Select all

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)
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: COMPILER ABORTS after issuing a valid error message

Post by dodicat »

You have to swing one way or the other
1)
Declare const Operator [](Byval n As Integer) As Ubyte
or the other
2)
While cast(udt,zo)[n] <> 0

Cannot have your cake and eat it at the same time, as they say.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: COMPILER ABORTS after issuing a valid error message

Post by fxm »

My purpose is not to discuss this error behavior, but only to point out the run-time compiler error that follows.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: COMPILER ABORTS after issuing a valid error message

Post by dodicat »

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!)
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: COMPILER ABORTS after issuing a valid error message

Post by coderJeff »

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.
fxm
Moderator
Posts: 12082
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: COMPILER ABORTS after issuing a valid error message

Post by fxm »

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.

Code: Select all

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)

This issue "Compiler aborts after rejecting the setting of a UDT reference to a temporary instance created by a constructor with optional parameter" is somewhat similar to bug report "#846 Compiler aborts when assigning a temporary copy of predefined data-type to a global variable" which has already been fixed.
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: COMPILER ABORTS after issuing a valid error message

Post by coderJeff »

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.
Post Reply