Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #1600
gptsarthak opened this issue Apr 5, 2023 · 2 comments · Fixed by #1672
Closed
Tracked by #1600

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

gptsarthak opened this issue Apr 5, 2023 · 2 comments · Fixed by #1672
Assignees
Labels
bug Something isn't working

Comments

@gptsarthak
Copy link
Contributor

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.

@certik certik added the bug Something isn't working label Apr 5, 2023
@certik certik mentioned this issue Apr 5, 2023
38 tasks
@certik
Copy link
Contributor

certik commented Apr 5, 2023

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!

@certik certik changed the title Error : Function code not generated Bug: "x : i32 = test()" fails at top level Apr 5, 2023
@Thirumalai-Shaktivel
Copy link
Collaborator

Thirumalai-Shaktivel commented Apr 6, 2023

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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants