← 输入框|github.com|刷新
Skip to content

Bug: "x : i32 = test()" fails at top level #1667

Closed

Description

@sarthakgupta0

Running

def test() -> i32:
    temp: i32 = 0
    return temp

x : i32 = test()
# print(x)  Will give segmentation fault

gives code generation error: Function code not generated for 'test' .

But declaring and assigning in different line

x : i32
x = test()
print(x)

compiles successfully.
Not sure if this is intentional. This type of code runs fine in CPython.

Activity

  1. added
    bug
    on Apr 5, 2023
  2. certik commented on Apr 5, 2023

    @certik
    Contributor

    That's a bug, in fact two separate bugs, one a segfault, the other one "code generation error: Function code not generated for 'test'", both need to be investigated and fixed. Given how simple the code is, I think this is a high priority bug, so I put it into our roadmap: #1600. Thanks for reporting it!

  3. changed the title [-]Error : Function code not generated[/-] [+]Bug: "x : i32 = test()" fails at top level[/+] on Apr 5, 2023
  4. Thirumalai-Shaktivel commented on Apr 6, 2023

    @Thirumalai-Shaktivel
    Collaborator

    I think, I can see two issues here:
    1.

    def test() -> i32:
        temp: i32 = 0
        return temp
    
    x : i32 = test()

    The above code doesn't have any statements, so function-call to _lpython_main_program is not happening
    2.

    def test() -> i32:
        temp: i32 = 0
        return temp
    
    x : i32 = test()
    print(x)

    Here x is a global_variable and we are initializing it using a function call. I think that is the reason for the seg_fault.

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions