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

No check when a function expects a return value #515

Closed
yzhang90 opened this issue Nov 26, 2017 · 5 comments
Closed

No check when a function expects a return value #515

yzhang90 opened this issue Nov 26, 2017 · 5 comments

Comments

@yzhang90
Copy link

What's your issue about?

Compiler should reject the following program

y: num[3]

@public
def foo(x: num[3]) -> num:
    self.y = x

because foo expects a return value of type num, however the current compiler still compiles.

How can it be fixed?

Need to keep track of the return type of each branch.

Cute Animal Picture

image

@fubuloubu
Copy link
Member

If you don't specify, it probably returns the null case, or 0 for num.

You're correct though, you should have some return statement if your function returns.

@fubuloubu
Copy link
Member

This is actually an interesting Formal Verification problem, for methods with lots of branches, is there a branch that does not return a value?

@DavidKnott
Copy link
Contributor

It gets even more fun if we force all branches to end in return or a throw 😄

@fubuloubu
Copy link
Member

fubuloubu commented Nov 27, 2017

Well, the easiest way to start is to just throw if no return value is set by end of execution. That solves this scenario easily.

But for future Formal Verification, we would implement a routine to check the program branches all contain a return statement and catch it at compile time instead of during runtime, as the above solution would provide (basically allowing us to remove the throw accounting for this issue)

@jacqueswww
Copy link
Contributor

Closing in favour of #590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants