Skip to content

There is something terribly wrong with scoping functions calls and returns #21

@mrombout

Description

@mrombout

The following code errors, stating that variable a does not exist.

This runs:

// test 1 - recursive variables
function test1(n) {
    if(n > 1) {
        return 6;
    }
    var a = n + 1;
    var b = n + 2;

    var a1 = test1(a);
    var b1 = test1(b);
    return a1 + b1;
}
var r1 = test1(0);
if(r1 === 18)
    print("test1 - OK!");
else
    print("test1 - FAIL!");

While this doesn't:

// test 2 - recursive return directly
function test2(n) {
    if(n > 1) {
        return 6;
    }
    var a = n + 1;
    var b = n + 2;

    return test2(a) + test2(b);
}
var r2 = test2(0);
if(r2 === 18)
    print("test2 - OK!");
else
    print("test2 - FAIL!");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions