NEWTON

NEWTON


Popular tags

    Cairo Error calling function: Expected 'function_name' to be a struct. Found: 'function'.

    Asked

    6 months ago

    2

    views


    0

    What is the cause of this issue and how do you solve it?

    This question was originally posted on Triality

      cairocairo-lang

    2 answers

    0

    If you run the following code, you will get the following error : Expected 'testFuncB' to be a struct. Found: 'function'.

    return (res=testFuncB(x))

    ^**********^

    func main():

    testFuncA()

    return ()

    end

    

    #This function calls another function to add one

    func testFuncA() -> (res : felt):

    let x = 1

    return (res=testFuncB(x))

    end

    

    #This function adds one to the input

    func testFuncB(input : felt) -> (res : felt):

    return (input+1)

    end

    If you unpack the call to testFuncB and set the variable in it's own line, you will solve the problem.

    func main():

    testFuncA()

    return ()

    end

    

    #This function calls another function to add one

    func testFuncA() -> (res : felt):

    let x = 1

    **let (res) = testFuncB(x)**

    return (res=res)

    end

    

    #This function adds one to the input

    func testFuncB(input : felt) -> (res : felt):

    return (input+1)

    end

    This answer was originally posted on Triality

    answered

    6 months ago

    0

    Looking at the documentation, there seems to be two possibilities

    This answer was originally posted on Triality

    answered

    6 months ago

    Your answer

    NEWTON

    NEWTON