It looks like saving a non-zero value from an unsigned variable/expression into a boolean bitfield will result in 0/false, while it should be -1/true.
type UDT
a : 1 as boolean
b : 1 as boolean
c : 1 as boolean
end type
#macro test(assignment)
scope
dim x as UDT
assignment
print x.a, x.b, x.c
end scope
#endmacro
scope
test(x.a = 1u)
test(x.b = 1u)
test(x.c = 1u)
end scope
print "---"
scope
dim value as uinteger = 1
test(x.a = value)
test(x.b = value)
test(x.c = value)
end scope
In your example, a, b and c are not booleans. They are integers. The following code works as expected:
Last edit: munair 2017-12-21
At best, one could say that the demonstrated code "a: 1 as boolean" (sort of an implicit bitfied) results in unpredictable behaviour. It shouldn't be allowed in my opinion. When inserting integers in-between, the results are "correct":
Remark: tested with FBC 1.06
Last edit: munair 2017-12-21
Internally, fbc handles the bitfields as FB_DATATYPE_UINT and conversion to BOOLEAN is getting optimized out prematurely.
What is method to handle bugs? branch, fix, update changelog, pull request? Then if accepted, close this ticket?
Fixed at
https://sourceforge.net/p/fbc/code/ci/c9bf95db7a87709e68597ae9bf5df287f4902fa6/tree/