Intermittent bug with #IF( %sym ) - %sym seems to be Null when it fails

Found a situation, which has intermittently plagued me for several years now, reproducible in C6 and C11.

Simple #IF( %sym ) which is being used to see if a value is present or not will resolve to false when it should resolve to true.

Its intermittent, could go weeks or months without seeing the problem and then suddenly I get it every time I run through a test and then it just starts working again. A reboot makes it work again.

When it resolves to false incorrectly, the actual value appears to be null and not zero.

Any suggestions?

TIA

That sounds a bit weird but I seem to recall struggling with something like that 25 or more years ago.

I seem to recall it was some scoping issue with #declare and it went away when I used #prompt instead.

Not sure if that is relevant but hope it helps.

Cheers

Geoff R

I think you are right on that one.

We use hidden #PROMPT statements instead of #DECLARE in many of our templates and as I recall it was to get rid of oddball problems like that.

Charles

This is a #Prompt, its not a #Declare.

I’m going to see if I can use IsNull( %sym ) in the #If() statement because I get nothing back, like a blank string when its should be zero.

I know not all clarion language functions can be used with template language code, but what appears to be a blank string using #Error could be the null like state of a variable.

That then means a 3rd state has been introduced to a True/False logic test and fails by defaulting to False. Technically its true or correct, but its not.

I might see what some Ai’s think to this idea and see what it comes up with.

Potentially its an attack vector, that DAB’s defensive coding wont pick up in a programming language, but this asserts the %sym is in a null state and IsNull may not always be available in a programming language.

Its causing an intermittent duplicate entry in my class writing template as highlighted in red.

I think you need to add VAREXISTS(%MySymbol)

#IF(VAREXISTS(%MySymbol) AND %MySymbol)

Well if its fails, I will still get a duplicate which is what I’m trying to avoid.

Its like a 3rd state ie Null is being added, so I have True, False & Null.

I could use VarExists() to flag an error has occurred, namely the Null state or Null condition has appeared.

You could try this

#IF(VAREXISTS(%MySymbol))
    #CASE(%MySymbol)
      #OF %True
    #OROF %FALSE
          RETURN %MySymbol
    #ELSE
          RETURN Whatever -- You can RETURN %False if 'null' = False
    #ENDCASE
#ENDIF

I’m using

#IF( NOT VarExists(%sym))
#Error('some msg')
#Else
#IF(NOT %sym)
#Insert(%AddDefaults)
#EndIF
#EndIF

Its an intermittent bug which I havent got to the bottom of what causes it, so for now the message will be sufficient.

I only got to the bottom of the fact the %sym appears to be null just the other day so hopefully this should be sufficient, but the existence of VarExists() says alot about how symbols & scope are handled.