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
[SR-10988] Suggest return
when the last statement of a multi-statement function body would be a valid return value
#53378
Comments
Comment by Giancarlo Buenaflor (JIRA) Hello, I would love to tackle this one as my first contribution if that is okay. |
Sounds great. Thanks buenaflor (JIRA User)! |
Hi, I'm new here, so sorry if I'm asking about obvious things. There seems to be no activity on this. Or is there a PR or something connected to this issue? https://github.com/apple/swift/pulls?q=SR-10988 turned up empty. If someone could point me towards the right files I could maybe try my luck. I haven't contributed anything yet and would be searching for an opportunity to get acquainted with the code base. |
Comment by Moritz Dietsche (JIRA) @jckarter I just submitted #42415 to address the first example in the description. The second is already implemented. Since this is my first PR to Swift, I wanted to keep it small. If you think the third one is desirable (don't fully understand the benefits tbh), I'm happy to tackle it as my next challenge. |
The first example was fixed by #42415. |
protocol Integer {
}
func foo() -> some Integer {
let x = 0
x
} Trying this snippet gets
@AnthonyLatsis Would it be alright if i made a patch to add in a warning EDIT: Nevermind, this is behaving correctly. |
Hm, I think we don't because |
Current behavior should be correct then, the protocol Integer {
}
struct Bar : Integer {
}
func foo() -> some Integer {
let x = Bar();
x
} |
Alright then, I think we can close this issue! |
@xedin What about the other two examples? |
Additional Detail from JIRA
md5: 3aba4962728f451223c8a69024161b98
Issue Description:
Now that we allow return statements to be elided in single-expression bodies, it's easy to end up during refactoring where you end up with multiple statements, but haven't yet added the
return
. We could detect when the last statement in a block is an ignored expr, and the type of the expr would be a valid return value, and offer a fixit, instead of sometimes-misleading error messages:The text was updated successfully, but these errors were encountered: