CHOOSE(0) constant-folded incorrectly

Description

For the following code...

toText(UNSIGNED1 i) := CHOOSE(i,'one','two','elsevalue');
OUTPUT(toText(0));
OUTPUT(toText(1));
OUTPUT(toText(2));
OUTPUT(toText(3));
OUTPUT(toText(4));

The values 1 and 2 yield their counterparts, and the values 3 and 4 yield 'elsevalue' as expected. However, passing 0 yields 0.

Shouldn't passing 0 yield 'elsevalue'?

I do see I'm violating the expected type of input, as the first parameter is described in the user's guide as "An arithmetic expression that results in a positive integer and determines which value parameter to return". However, given the elsevalue is broadly described as "The value to return when the expression returns an out-of-range value", it seems more logical to return it rather than lapse into undefined behavior.

Conclusion

None

is duplicated by

Activity

Show:

Richard Chapman November 11, 2015 at 1:48 PM

I think this is a constant-folding bug - toText(nofold(0)) returns elseValue as expected.

Todd Leonard October 29, 2015 at 2:22 PM

In contrast, CHOOSE(-1) does return the elsevalue... but I'm guessing this is because it's interpreted internally as 255 or similar due to a conversion to some UNSIGNEDn, and not due to range checking at the low end.

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Components

Assignee

Reporter

Priority

Fix versions

Created October 29, 2015 at 2:13 PM
Updated February 10, 2016 at 6:16 PM
Resolved November 16, 2015 at 12:50 PM

Flag notifications