Monday, February 23, 2015

CFScript bug?

An extra semicolon at the end of "if" block is causing a lot of head scratching for me recently. Please see the code snippet below. Expected output should be:
Figure 1. Expected Output
However, below is the actual output:
Figure 2. Actual Output
Now, please notice this extra ";" at the end of line 6. If I remove it, everything will just work as expected.
    private struct function test() {
        if(1 == 1) {
            if(1 == 0) {
            }; //<- look at here
            return {data = 1};
        return {data = 2};
Due to the lack of specifications for CFScript language, I cannot tell if this grammar is even allowed. But I can tell you this: the journey of discovering and finding the root cause of this problem is not fun at all!


CFScript fall through the "if-else" statement, and did not return to caller from the expected branch.


An extra semicolon at the end of a block is the root cause.

No comments: