UNSIGNED gets implicitly cast to BOOLEAN in spite of documentation to the contrary

Description

Reading the language reference, I’m not sure if an implicit cast of an UNSIGNED to a BOOLEAN is expected or not (not sure what the highlighted section below was meaning to convey):

 During expression evaluation, different value types may be implicitly cast in order to properly evaluate the expression. Implicit casting always means promoting one value type to another: INTEGER to STRING or INTEGER to REAL. BOOLEAN types may not be involved in mixed mode expressions.

 __  

I was looking at an issue recently, and the code effectively was written like this (simplified example):

     Somefunc(STRING str, BOOLEAN isConfirmed = FALSE, UNSIGNED seq = 1) := FUNCTION

             s := str + seq;

             c := IF(isConfirmed, 'CONFIRMED: ', 'NOT CONFIRMED: ');

             RETURN c + s;                   

      END;

 The calling code was not correctly aligned with the function parameters:

      Foo := Somefunc(‘bar’, 8);

 This produced no warning, but didn’t function the way the developer intended. 

 

If there is concern that changing this behavior would break a lot of existing code, it would at least be beneficial for this to generate a warning.

 

 

Conclusion

None

Activity

Show:

Gavin Halliday January 7, 2020 at 10:32 AM

I have released a fix for 7.8 to report a warning when this occurs.  There are enough issues in existing queries that I made it a warning rather than an error - although I plan to change the default error level at a later date (e.g., in 9.0).

I found one example which now fails (fn_GetBusinessRecordVerification), which previously worked is returning a set of integers as a set of boolean.  Adding an explicit cast to (SET OF BOOLEAN) fixes that issue.

 

Fixed
Pinned fields
Click on the next to a field label to start pinning.
Created January 6, 2020 at 2:22 PM
Updated January 10, 2020 at 11:11 AM
Resolved January 10, 2020 at 11:11 AM

Flag notifications