-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[lib/Sema] Suggest return
when the last statement would be a valid …
#42415
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
Conversation
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
Thank you @LucianoPAlmeida for your review. I implemented the suggested changes in the latest commit. |
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…statement-of-a-multi-statement-function-body-would-be-a-valid-return-value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the check makes sense. Could you please add some more tests where e.g. some
type is a protocol composition and one case where result doesn't conform?
…statement-of-a-multi-statement-function-body-would-be-a-valid-return-value
…statement-of-a-multi-statement-function-body-would-be-a-valid-return-value
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
@swift-ci please test |
Looks great now, thank you @moritzdietsche! |
Thanks for your review and help! |
@swift-ci Please test Linux Platform |
@moritzdietsche Looks like you need to update one more test. |
Ah, sorry @xedin ... I just looked the Jenkins and saw |
No worries! :) |
…return value Addresses SR-10988. When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword. This changes extends this behavior to functions with opaque return types.
@LucianoPAlmeida I think I'm ready for a new test run. |
@swift-ci Please test |
…return value
When a multi-statement function body contains no return keyword but the last statement would be a valid return value, the compiler currently proposes a fixit to add the return keyword.
This changes extends this behavior to functions with opaque return types.
Note: SR-10988 proposes to extend this behavior (for non-opaque and opaque return types) further by looking for valid return values in
if
statements. I do not fully understand the benefits of having this but will gladly provide an implementation if it is decided that such functionality is desired.Resolves #53378