Skip to content

[Bug] Function calls fail when the called function is defined later #142

@arapower

Description

@arapower

The following code produces an error:

fun call(key){
    if key == "some" {
        return some()
    } else {
        return other()
    }
}

fun some(){
    echo "SOME"
    return call("END")
}

fun other(){
    echo "OTHER"
    return call("END")
}

main {
    let keyword = "some"
    echo call(keyword)
}
$ amber ./sample.ab
 ERROR 
Function 'some' does not exist
at ./sample.ab:3:16

2|     if key == "some" {
3|         return some()
4|     } else {

It seems that when the function call tries to call functions some and other, which are defined later, an error occurs. If the called function is not defined before the calling function, it results in an error. This prevents writing recursive processes across multiple functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions