Skip to content

Inner functions not present in the functions table #2

Description

@skushagra

While exploring the codebase with the maker himself, we encountered a bug where for the code below

let a = 10;
let b = 15;

function max(a, b) {
    function inner_max(a, b) {
        if (a > b) {
        return a;
        } else {
            return b;
        }
    }
    
    return inner_max(a,b);
}

let m = max(a, b);

the function will not be present in the final functions table prepared and there when when this program is executed

Program {
    main: [
        LoadConst(Number(10)), DeclareVar("a"), 
        LoadConst(Number(15)), DeclareVar("b"),
        LoadVar("a"),
        LoadVar("b"),
        
        CallFunction("max", 2), 
        DeclareVar("m")
    ], functions: {
        "max": FunctionBytecode { params: ["a", "b"], instructions: [
            LoadVar("a"), 
            LoadVar("b"), 
            CallFunction("inner_max", 2), Return
        ]}
    } 
}

function inner_max will give the error

thread 'main' (25133346) panicked at src/vm/mod.rs:256:57:
undefined function

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions