Unexpected behavior of fn!displayvalue() in combination with fn!error()

I observed that if you use fn!error() in the defaultValue of the fn!displayvalue() function, the fn!displayvalue() behaves different.
It always returns the error message, even if we have a match in the array and replacementarray
Eg:
with(
local!num: 1,

fn!displayvalue(
local!num,
{2,1,3,4},
{"Num2", "Num1", "Num3", "Num4"},
fn!error("default value should not be evaluated")
)
)

In the code snippet, as per the usual behavior of displayvalue(), the expected output is "Num1". But, instead it returns the error message - it means the default value gets evaluated even if we have a match - and it is returned. I believe the fn!error() functions behaves like a Java Exception or Error.

But, lets take another example of using fn!if() with fn!error()
if(3>2, "Correct", fn!error("Not Correct"))

This returns "Co...

OriginalPostID-236519

  Discussion posts and replies are publicly visible

Parents
  • @joshl, you are right - but just a small correction, I think it is trying to cast to the type of "replacement"
    Try fn!displayvalue(9, {1,2,3},{"hello", "bye"}, true )
    In the output, you get true - but its not Boolean or Number, it is Text.
    So, we can conclude that default value gets cast to the type of "replacement". I also tried fn!displayvalue(9, {1,2,3},{4.5,8.9,6.7}, true ).
    It returned 1 (Number-Decimal).
Reply
  • @joshl, you are right - but just a small correction, I think it is trying to cast to the type of "replacement"
    Try fn!displayvalue(9, {1,2,3},{"hello", "bye"}, true )
    In the output, you get true - but its not Boolean or Number, it is Text.
    So, we can conclude that default value gets cast to the type of "replacement". I also tried fn!displayvalue(9, {1,2,3},{4.5,8.9,6.7}, true ).
    It returned 1 (Number-Decimal).
Children
No Data