Skip to content

[code-completion] Add type context for single-expression function bodies #23587

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

Merged
merged 3 commits into from
Apr 25, 2019

Conversation

benlangmuir
Copy link
Contributor

@benlangmuir benlangmuir commented Mar 27, 2019

Extend the support for single-expression closures to handle single-expression functions of all kinds. This allows, e.g.

func foo() -> MyEnum { .<here> }

to complete members of MyEnum.

rdar://problem/48938531


Note: this conceptually depends on #23251, which implements the language feature

Extend the support for single-expression closures to handle
single-expression functions of all kinds. This allows, e.g.

    func foo() -> MyEnum { .<here> }

to complete members of `MyEnum`.
This adds an implicit body so that we can dig out the return type
context the same way as a normal function. For now, we are also treating
the first expression in a multi-statement implicit getter body the same
way; we'll need to refactor how we complete in accessors to
differentiate those cases.
@benlangmuir
Copy link
Contributor Author

@swift-ci please test

@benlangmuir benlangmuir requested a review from rintaro March 27, 2019 00:40
@benlangmuir
Copy link
Contributor Author

@nate-chandler FYI this PR adds code-completion support for your "allow return to be omitted" change. The implementation doesn't require your changes so far, so I've left it a separate PR to make it easier to review.

@benlangmuir
Copy link
Contributor Author

benlangmuir commented Mar 27, 2019

@rintaro I added the tests for init, deinit, and top-level vars. I was wrong about handling .none in a failable initializer; that doesn't work even with explicit return. The only test case that isn't already working is

init?() { #^A^# }

This case gets nil, but doesn't have the correct type context. The reason is that the type-checker adds an implicit return statement here after the code-completion expression, which doesn't happen for any other decls. We could handle this if we cared, but it would make checking the body more complicated. Since there is no legal unresolved members here it doesn't have any practical effect anyway, so I left it.

@benlangmuir
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - e255bac

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e255bac

@benlangmuir benlangmuir marked this pull request as ready for review April 25, 2019 16:38
@benlangmuir
Copy link
Contributor Author

@swift-ci please smoke test

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

Successfully merging this pull request may close these issues.

3 participants